forge
Explore
Log in

Don't you dare go Hollow

The person page's photo opens in the viewer too

Browse files at this commit

30e29dc36be8769e4998b1148a6499997858fe52Ahmet Kaan GümüşParent: e1ca55f
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.rsmodified+62 -0
@@ -99,6 +99,68 @@ pub(crate) async fn avatar(cx: &Cx, person: &Person, extra: &str) -> Result {
9999 }
100100 }
101101
102+/// The avatar overlay: with a photo set, the avatar click opens the file
103+/// viewer's chrome (`detail.rs`'s `file_viewer_modal` — the
104+/// `.modal-scrim.viewer-scrim` scrim and the `.modal.viewer` panel around a
105+/// `.viewer-media` image) around the same `/photo/{id}?v=` URL the avatar
106+/// reads. Built here because the overlay has no server state behind it — no
107+/// route, no query parameter, nothing to render — so it is client-built and
108+/// `__izAdded`'d. Closing is not wired here at all: the stretched
109+/// `.viewer-close` anchor and the scrim click are the global handlers in the
110+/// soft-nav script above, and Escape is `detail.rs`'s `escape_closes`
111+/// (priority 90), which the page emits alongside this script. The picture is
112+/// read off the avatar's own `<img>` at click time, stamp included, so a
113+/// fresh upload is the fresh bytes. The Change half serves the settings
114+/// identity row alone: it hands the click to the hidden file input, whose
115+/// change the shared autosubmit listener posts as the photo form. Emitted by
116+/// the settings page and the person page — every surface that draws a
117+/// clickable `.avatar-view`.
118+pub(crate) async fn avatar_script(cx: &Cx) -> Result {
119+ use topcoat::view::Unescaped;
120+ const JS: &str = "\
121+ (function () { \
122+ if (window.__izAvatar) { return; } \
123+ window.__izAvatar = true; \
124+ document.addEventListener('click', function (e) { \
125+ var view = e.target.closest ? e.target.closest('.avatar-view') : null; \
126+ if (view) { \
127+ var img = view.querySelector('img.avatar'); \
128+ if (!img || document.querySelector('.viewer-scrim')) { return; } \
129+ var scrim = document.createElement('div'); \
130+ scrim.className = 'modal-scrim viewer-scrim'; \
131+ var close = document.createElement('a'); \
132+ close.className = 'viewer-close'; \
133+ close.href = window.location.href; \
134+ var label = view.getAttribute('data-close-label'); \
135+ if (label) { close.setAttribute('aria-label', label); } \
136+ var media = document.createElement('img'); \
137+ media.className = 'viewer-media'; \
138+ media.src = img.src; \
139+ media.alt = img.alt; \
140+ var body = document.createElement('div'); \
141+ body.className = 'viewer-body'; \
142+ body.appendChild(media); \
143+ var box = document.createElement('div'); \
144+ box.className = 'modal viewer'; \
145+ box.tabIndex = -1; \
146+ box.appendChild(body); \
147+ scrim.appendChild(close); \
148+ scrim.appendChild(box); \
149+ document.body.appendChild(window.__izAdded(scrim)); \
150+ box.focus(); \
151+ return; \
152+ } \
153+ var change = e.target.closest ? e.target.closest('[data-avatar-change]') : null; \
154+ if (change) { \
155+ var row = change.closest('.identity-row'); \
156+ var input = row ? row.querySelector('.file-upload-input') : null; \
157+ if (input) { input.click(); } \
158+ } \
159+ }, true); \
160+ })();";
161+ view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }
162+}
163+
102164 /// The topbar's signed-in identity: the display name, opening on hover or
103165 /// focus onto details (name, address, role) and sign-out. Shared by every
104166 /// signed-in page's topbar (board, settings, mail rules, logs).
crates/iz-web/src/people.rsmodified+13 -2
@@ -114,7 +114,10 @@ async fn people_page(cx: &Cx) -> Result {
114114 8,
115115 FeedPage::Newest,
116116 Dir::Newest,
117- &ActivityFilter { actor: Some(person.id.clone()), ..Default::default() },
117+ &ActivityFilter {
118+ actor: Some(person.id.clone()),
119+ ..Default::default()
120+ },
118121 )
119122 .await?;
120123
@@ -130,7 +133,13 @@ async fn people_page(cx: &Cx) -> Result {
130133 <main class="people-shell">
131134 <section class="panel person-card">
132135 <div class="person-head">
133- (crate::layout::avatar(cx, &who, "avatar-xl").await?)
136+ if person.has_photo {
137+ <button class="avatar-view" type="button" data-close-label=(t(lang, Key::Close))>
138+ (crate::layout::avatar(cx, &who, "avatar-xl").await?)
139+ </button>
140+ } else {
141+ (crate::layout::avatar(cx, &who, "avatar-xl").await?)
142+ }
134143 <div class="person-heading">
135144 <h2 class="person-name">(person.display_name.clone())</h2>
136145 <div class="person-marks">
@@ -216,5 +225,7 @@ async fn people_page(cx: &Cx) -> Result {
216225 </main>
217226
218227 (crate::layout::escape_script(cx).await?)
228+ (crate::detail::escape_closes(cx).await?)
229+ (crate::layout::avatar_script(cx).await?)
219230 }
220231 }
crates/iz-web/src/settings.rsmodified+14 -67
@@ -957,7 +957,10 @@ async fn send_message(
957957 };
958958 let subject = input.subject.trim();
959959 if subject.is_empty() {
960- return Ok(saved_or_refused("send_message", Some(Refusal::EmptySubject)));
960+ return Ok(saved_or_refused(
961+ "send_message",
962+ Some(Refusal::EmptySubject),
963+ ));
961964 }
962965 let body = input.body.trim();
963966 if body.is_empty() {
@@ -974,7 +977,12 @@ async fn send_message(
974977 } else {
975978 match members.into_iter().find(|member| member.id == input.to) {
976979 Some(member) => vec![member.email],
977- None => return Ok(saved_or_refused("send_message", Some(Refusal::NoSuchMember))),
980+ None => {
981+ return Ok(saved_or_refused(
982+ "send_message",
983+ Some(Refusal::NoSuchMember),
984+ ));
985+ }
978986 }
979987 };
980988 let now = time::OffsetDateTime::now_utc();
@@ -1193,9 +1201,7 @@ fn is_origin(value: &str) -> bool {
11931201 return false;
11941202 };
11951203 let host = rest.split('/').next().unwrap_or_default();
1196- !host.is_empty()
1197- && !host.contains('@')
1198- && !value.chars().any(char::is_whitespace)
1204+ !host.is_empty() && !host.contains('@') && !value.chars().any(char::is_whitespace)
11991205 }
12001206
12011207 /// 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 {
13161322 None
13171323 };
13181324 let (limits, allowed_types) = if administers {
1319- let (attachment, photo, types, batch, reminder) = limits_now(cx, &user.workspace_id).await?;
1325+ let (attachment, photo, types, batch, reminder) =
1326+ limits_now(cx, &user.workspace_id).await?;
13201327 (Some((attachment, photo, batch, reminder)), types)
13211328 } else {
13221329 (None, Vec::new())
@@ -1954,66 +1961,6 @@ async fn settings_page(cx: &Cx) -> Result {
19541961 (crate::dropdown::dropdown_script(cx).await?)
19551962 (crate::layout::escape_script(cx).await?)
19561963 (crate::detail::escape_closes(cx).await?)
1957- (avatar_script(cx).await?)
1964+ (crate::layout::avatar_script(cx).await?)
19581965 }
19591966 }
1960-
1961-/// The profile photo's overlay: with a photo set, the avatar click opens the
1962-/// file viewer's chrome (`detail.rs`'s `file_viewer_modal` — the
1963-/// `.modal-scrim.viewer-scrim` scrim and the `.modal.viewer` panel around a
1964-/// `.viewer-media` image) around the same `/photo/{id}?v=` URL the avatar
1965-/// reads. Built here because the overlay has no server state behind it — no
1966-/// route, no query parameter, nothing to render — so it is client-built and
1967-/// `__izAdded`'d. Closing is not wired here at all: the stretched
1968-/// `.viewer-close` anchor and the scrim click are the global handlers in
1969-/// `layout.rs`'s soft-nav script, and Escape is `detail.rs`'s
1970-/// `escape_closes` (priority 90), emitted alongside this script. The picture
1971-/// is read off the avatar's own `<img>` at click time, stamp included, so a
1972-/// fresh upload is the fresh bytes. Change hands the click to the hidden
1973-/// file input, whose change the shared autosubmit listener in `layout.rs`
1974-/// posts as the photo form.
1975-async fn avatar_script(cx: &Cx) -> Result {
1976- use topcoat::view::Unescaped;
1977- const JS: &str = "\
1978- (function () { \
1979- if (window.__izAvatar) { return; } \
1980- window.__izAvatar = true; \
1981- document.addEventListener('click', function (e) { \
1982- var view = e.target.closest ? e.target.closest('.avatar-view') : null; \
1983- if (view) { \
1984- var img = view.querySelector('img.avatar'); \
1985- if (!img || document.querySelector('.viewer-scrim')) { return; } \
1986- var scrim = document.createElement('div'); \
1987- scrim.className = 'modal-scrim viewer-scrim'; \
1988- var close = document.createElement('a'); \
1989- close.className = 'viewer-close'; \
1990- close.href = window.location.href; \
1991- var label = view.getAttribute('data-close-label'); \
1992- if (label) { close.setAttribute('aria-label', label); } \
1993- var media = document.createElement('img'); \
1994- media.className = 'viewer-media'; \
1995- media.src = img.src; \
1996- media.alt = img.alt; \
1997- var body = document.createElement('div'); \
1998- body.className = 'viewer-body'; \
1999- body.appendChild(media); \
2000- var box = document.createElement('div'); \
2001- box.className = 'modal viewer'; \
2002- box.tabIndex = -1; \
2003- box.appendChild(body); \
2004- scrim.appendChild(close); \
2005- scrim.appendChild(box); \
2006- document.body.appendChild(window.__izAdded(scrim)); \
2007- box.focus(); \
2008- return; \
2009- } \
2010- var change = e.target.closest ? e.target.closest('[data-avatar-change]') : null; \
2011- if (change) { \
2012- var row = change.closest('.identity-row'); \
2013- var input = row ? row.querySelector('.file-upload-input') : null; \
2014- if (input) { input.click(); } \
2015- } \
2016- }, true); \
2017- })();";
2018- view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }
2019-}
crates/iz-web/tests/browser/photo.mjsmodified+25 -0
@@ -211,6 +211,31 @@ if (!failures.length) {
211211 }
212212 }
213213
214+// The person page wears the same trigger: its xl avatar opens the same
215+// overlay, at its own size — the settings row's 64px must not follow it.
216+if (!failures.length) {
217+ const ownId = await page.evaluate(() => {
218+ const img = document.querySelector('.identity-row img.avatar');
219+ const m = img && (img.getAttribute('src') || '').match(/\/photo\/([^?]+)/);
220+ return m ? m[1] : null;
221+ });
222+ if (!ownId) {
223+ failures.push('no own photo id to reach the person page with');
224+ } else {
225+ await page.goto(`${base}/people/${ownId}`, { waitUntil: 'networkidle' });
226+ const wide = await page.evaluate(() => {
227+ const img = document.querySelector('.person-head .avatar-view img.avatar');
228+ return img ? img.getBoundingClientRect().width : 0;
229+ });
230+ if (wide <= 64) failures.push(`the person page's avatar shrank to ${wide}px inside the trigger`);
231+ if (await openViewer('person-page')) {
232+ await page.screenshot({ path: `${shots}/person-photo-viewer.png` });
233+ await page.keyboard.press('Escape');
234+ await viewerGone('person-page');
235+ }
236+ }
237+}
238+
214239 await browser.close();
215240
216241 note(`page errors ${errors.length ? errors.join(' | ') : 'none'}`);
style/main.scssmodified+12 -8
@@ -1064,24 +1064,28 @@ img.avatar {
10641064 gap: 14px;
10651065 }
10661066
1067-// The two faces of the 64px profile picture box: the picker label and, once
1068-// a photo exists, the viewer trigger.
1067+// The two faces of the profile picture box: the picker label and, once a
1068+// photo exists, the viewer trigger. The person page's own card wears the
1069+// trigger too — the box rules are shared, the size is not.
10691070 .avatar-upload,
10701071 .avatar-view {
10711072 position: relative;
10721073 flex: none;
10731074 cursor: pointer;
10741075
1075- .avatar {
1076- width: 64px;
1077- height: 64px;
1078- font-size: 20px;
1079- }
1080-
10811076 // The name tooltip has no job on your own picture.
10821077 .avatar[data-name]:hover::after { content: none; }
10831078 }
10841079
1080+// The settings row's picture is 64px whatever size class the avatar wears;
1081+// the person card's keeps its xl.
1082+.identity-row .avatar-upload .avatar,
1083+.identity-row .avatar-view .avatar {
1084+ width: 64px;
1085+ height: 64px;
1086+ font-size: 20px;
1087+}
1088+
10851089 // The trigger is the label's box with a button's chrome stripped.
10861090 .avatar-view {
10871091 appearance: none;