From 30e29dc36be8769e4998b1148a6499997858fe52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 4 Sep 2026 03:09:40 +0300 Subject: [PATCH] The person page's photo opens in the viewer too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The overlay lived only where it was built: the settings identity row. The person card's avatar now wears the same trigger — the script moves to layout.rs beside avatar() and both pages emit it, Escape rides the same priority-90 resolver, and the identity row's 64px sizing is scoped to the row so the card keeps its xl. The browser pass walks the person page: overlay opens, closes, and the avatar keeps its size. --- crates/iz-web/src/layout.rs | 62 ++++++++++++++++++++ crates/iz-web/src/people.rs | 15 ++++- crates/iz-web/src/settings.rs | 81 +++++---------------------- crates/iz-web/tests/browser/photo.mjs | 25 +++++++++ style/main.scss | 20 ++++--- 5 files changed, 126 insertions(+), 77 deletions(-) diff --git a/crates/iz-web/src/layout.rs b/crates/iz-web/src/layout.rs index ba362a5..610a15e 100644 --- a/crates/iz-web/src/layout.rs +++ b/crates/iz-web/src/layout.rs @@ -99,6 +99,68 @@ pub(crate) async fn avatar(cx: &Cx, person: &Person, extra: &str) -> Result { } } +/// The avatar overlay: with a photo set, the avatar click opens the file +/// viewer's chrome (`detail.rs`'s `file_viewer_modal` — the +/// `.modal-scrim.viewer-scrim` scrim and the `.modal.viewer` panel around a +/// `.viewer-media` image) around the same `/photo/{id}?v=` URL the avatar +/// reads. Built here because the overlay has no server state behind it — no +/// route, no query parameter, nothing to render — so it is client-built and +/// `__izAdded`'d. Closing is not wired here at all: the stretched +/// `.viewer-close` anchor and the scrim click are the global handlers in the +/// soft-nav script above, and Escape is `detail.rs`'s `escape_closes` +/// (priority 90), which the page emits alongside this script. The picture is +/// read off the avatar's own `` at click time, stamp included, so a +/// fresh upload is the fresh bytes. The Change half serves the settings +/// identity row alone: it hands the click to the hidden file input, whose +/// change the shared autosubmit listener posts as the photo form. Emitted by +/// the settings page and the person page — every surface that draws a +/// clickable `.avatar-view`. +pub(crate) async fn avatar_script(cx: &Cx) -> Result { + use topcoat::view::Unescaped; + const JS: &str = "\ + (function () { \ + if (window.__izAvatar) { return; } \ + window.__izAvatar = true; \ + document.addEventListener('click', function (e) { \ + var view = e.target.closest ? e.target.closest('.avatar-view') : null; \ + if (view) { \ + var img = view.querySelector('img.avatar'); \ + if (!img || document.querySelector('.viewer-scrim')) { return; } \ + var scrim = document.createElement('div'); \ + scrim.className = 'modal-scrim viewer-scrim'; \ + var close = document.createElement('a'); \ + close.className = 'viewer-close'; \ + close.href = window.location.href; \ + var label = view.getAttribute('data-close-label'); \ + if (label) { close.setAttribute('aria-label', label); } \ + var media = document.createElement('img'); \ + media.className = 'viewer-media'; \ + media.src = img.src; \ + media.alt = img.alt; \ + var body = document.createElement('div'); \ + body.className = 'viewer-body'; \ + body.appendChild(media); \ + var box = document.createElement('div'); \ + box.className = 'modal viewer'; \ + box.tabIndex = -1; \ + box.appendChild(body); \ + scrim.appendChild(close); \ + scrim.appendChild(box); \ + document.body.appendChild(window.__izAdded(scrim)); \ + box.focus(); \ + return; \ + } \ + var change = e.target.closest ? e.target.closest('[data-avatar-change]') : null; \ + if (change) { \ + var row = change.closest('.identity-row'); \ + var input = row ? row.querySelector('.file-upload-input') : null; \ + if (input) { input.click(); } \ + } \ + }, true); \ + })();"; + view! { cx => } +} + /// The topbar's signed-in identity: the display name, opening on hover or /// focus onto details (name, address, role) and sign-out. Shared by every /// signed-in page's topbar (board, settings, mail rules, logs). diff --git a/crates/iz-web/src/people.rs b/crates/iz-web/src/people.rs index 3f2c2cf..5d73c71 100644 --- a/crates/iz-web/src/people.rs +++ b/crates/iz-web/src/people.rs @@ -114,7 +114,10 @@ async fn people_page(cx: &Cx) -> Result { 8, FeedPage::Newest, Dir::Newest, - &ActivityFilter { actor: Some(person.id.clone()), ..Default::default() }, + &ActivityFilter { + actor: Some(person.id.clone()), + ..Default::default() + }, ) .await?; @@ -130,7 +133,13 @@ async fn people_page(cx: &Cx) -> Result {
- (crate::layout::avatar(cx, &who, "avatar-xl").await?) + if person.has_photo { + + } else { + (crate::layout::avatar(cx, &who, "avatar-xl").await?) + }

(person.display_name.clone())

@@ -216,5 +225,7 @@ async fn people_page(cx: &Cx) -> Result {
(crate::layout::escape_script(cx).await?) + (crate::detail::escape_closes(cx).await?) + (crate::layout::avatar_script(cx).await?) } } diff --git a/crates/iz-web/src/settings.rs b/crates/iz-web/src/settings.rs index ac7ec72..b62702d 100644 --- a/crates/iz-web/src/settings.rs +++ b/crates/iz-web/src/settings.rs @@ -957,7 +957,10 @@ async fn send_message( }; let subject = input.subject.trim(); if subject.is_empty() { - return Ok(saved_or_refused("send_message", Some(Refusal::EmptySubject))); + return Ok(saved_or_refused( + "send_message", + Some(Refusal::EmptySubject), + )); } let body = input.body.trim(); if body.is_empty() { @@ -974,7 +977,12 @@ async fn send_message( } else { match members.into_iter().find(|member| member.id == input.to) { Some(member) => vec![member.email], - None => return Ok(saved_or_refused("send_message", Some(Refusal::NoSuchMember))), + None => { + return Ok(saved_or_refused( + "send_message", + Some(Refusal::NoSuchMember), + )); + } } }; let now = time::OffsetDateTime::now_utc(); @@ -1193,9 +1201,7 @@ fn is_origin(value: &str) -> bool { return false; }; let host = rest.split('/').next().unwrap_or_default(); - !host.is_empty() - && !host.contains('@') - && !value.chars().any(char::is_whitespace) + !host.is_empty() && !host.contains('@') && !value.chars().any(char::is_whitespace) } /// The refusal that landed on this call's redirect, if any, and this call's @@ -1316,7 +1322,8 @@ async fn settings_page(cx: &Cx) -> Result { None }; let (limits, allowed_types) = if administers { - let (attachment, photo, types, batch, reminder) = limits_now(cx, &user.workspace_id).await?; + let (attachment, photo, types, batch, reminder) = + limits_now(cx, &user.workspace_id).await?; (Some((attachment, photo, batch, reminder)), types) } else { (None, Vec::new()) @@ -1954,66 +1961,6 @@ async fn settings_page(cx: &Cx) -> Result { (crate::dropdown::dropdown_script(cx).await?) (crate::layout::escape_script(cx).await?) (crate::detail::escape_closes(cx).await?) - (avatar_script(cx).await?) + (crate::layout::avatar_script(cx).await?) } } - -/// The profile photo's overlay: with a photo set, the avatar click opens the -/// file viewer's chrome (`detail.rs`'s `file_viewer_modal` — the -/// `.modal-scrim.viewer-scrim` scrim and the `.modal.viewer` panel around a -/// `.viewer-media` image) around the same `/photo/{id}?v=` URL the avatar -/// reads. Built here because the overlay has no server state behind it — no -/// route, no query parameter, nothing to render — so it is client-built and -/// `__izAdded`'d. Closing is not wired here at all: the stretched -/// `.viewer-close` anchor and the scrim click are the global handlers in -/// `layout.rs`'s soft-nav script, and Escape is `detail.rs`'s -/// `escape_closes` (priority 90), emitted alongside this script. The picture -/// is read off the avatar's own `` at click time, stamp included, so a -/// fresh upload is the fresh bytes. Change hands the click to the hidden -/// file input, whose change the shared autosubmit listener in `layout.rs` -/// posts as the photo form. -async fn avatar_script(cx: &Cx) -> Result { - use topcoat::view::Unescaped; - const JS: &str = "\ - (function () { \ - if (window.__izAvatar) { return; } \ - window.__izAvatar = true; \ - document.addEventListener('click', function (e) { \ - var view = e.target.closest ? e.target.closest('.avatar-view') : null; \ - if (view) { \ - var img = view.querySelector('img.avatar'); \ - if (!img || document.querySelector('.viewer-scrim')) { return; } \ - var scrim = document.createElement('div'); \ - scrim.className = 'modal-scrim viewer-scrim'; \ - var close = document.createElement('a'); \ - close.className = 'viewer-close'; \ - close.href = window.location.href; \ - var label = view.getAttribute('data-close-label'); \ - if (label) { close.setAttribute('aria-label', label); } \ - var media = document.createElement('img'); \ - media.className = 'viewer-media'; \ - media.src = img.src; \ - media.alt = img.alt; \ - var body = document.createElement('div'); \ - body.className = 'viewer-body'; \ - body.appendChild(media); \ - var box = document.createElement('div'); \ - box.className = 'modal viewer'; \ - box.tabIndex = -1; \ - box.appendChild(body); \ - scrim.appendChild(close); \ - scrim.appendChild(box); \ - document.body.appendChild(window.__izAdded(scrim)); \ - box.focus(); \ - return; \ - } \ - var change = e.target.closest ? e.target.closest('[data-avatar-change]') : null; \ - if (change) { \ - var row = change.closest('.identity-row'); \ - var input = row ? row.querySelector('.file-upload-input') : null; \ - if (input) { input.click(); } \ - } \ - }, true); \ - })();"; - view! { cx => } -} diff --git a/crates/iz-web/tests/browser/photo.mjs b/crates/iz-web/tests/browser/photo.mjs index 13e0572..c669ff6 100644 --- a/crates/iz-web/tests/browser/photo.mjs +++ b/crates/iz-web/tests/browser/photo.mjs @@ -211,6 +211,31 @@ if (!failures.length) { } } +// The person page wears the same trigger: its xl avatar opens the same +// overlay, at its own size — the settings row's 64px must not follow it. +if (!failures.length) { + const ownId = await page.evaluate(() => { + const img = document.querySelector('.identity-row img.avatar'); + const m = img && (img.getAttribute('src') || '').match(/\/photo\/([^?]+)/); + return m ? m[1] : null; + }); + if (!ownId) { + failures.push('no own photo id to reach the person page with'); + } else { + await page.goto(`${base}/people/${ownId}`, { waitUntil: 'networkidle' }); + const wide = await page.evaluate(() => { + const img = document.querySelector('.person-head .avatar-view img.avatar'); + return img ? img.getBoundingClientRect().width : 0; + }); + if (wide <= 64) failures.push(`the person page's avatar shrank to ${wide}px inside the trigger`); + if (await openViewer('person-page')) { + await page.screenshot({ path: `${shots}/person-photo-viewer.png` }); + await page.keyboard.press('Escape'); + await viewerGone('person-page'); + } + } +} + await browser.close(); note(`page errors ${errors.length ? errors.join(' | ') : 'none'}`); diff --git a/style/main.scss b/style/main.scss index e4f1039..6078e0d 100644 --- a/style/main.scss +++ b/style/main.scss @@ -1064,24 +1064,28 @@ img.avatar { gap: 14px; } -// The two faces of the 64px profile picture box: the picker label and, once -// a photo exists, the viewer trigger. +// The two faces of the profile picture box: the picker label and, once a +// photo exists, the viewer trigger. The person page's own card wears the +// trigger too — the box rules are shared, the size is not. .avatar-upload, .avatar-view { position: relative; flex: none; cursor: pointer; - .avatar { - width: 64px; - height: 64px; - font-size: 20px; - } - // The name tooltip has no job on your own picture. .avatar[data-name]:hover::after { content: none; } } +// The settings row's picture is 64px whatever size class the avatar wears; +// the person card's keeps its xl. +.identity-row .avatar-upload .avatar, +.identity-row .avatar-view .avatar { + width: 64px; + height: 64px; + font-size: 20px; +} + // The trigger is the label's box with a button's chrome stripped. .avatar-view { appearance: none;