The person page's photo opens in the viewer too
Browse files at this commit30e29dc36be8769e4998b1148a6499997858fe52Parent: e1ca55f5 changed files +126 -77
- crates/iz-web/src/layout.rs +62 -0
- crates/iz-web/src/people.rs +13 -2
- crates/iz-web/src/settings.rs +14 -67
- crates/iz-web/tests/browser/photo.mjs +25 -0
- style/main.scss +12 -8
crates/iz-web/src/layout.rsmodified+62 -0
| @@ -99,6 +99,68 @@ pub(crate) async fn avatar(cx: &Cx, person: &Person, extra: &str) -> Result { | ||
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
| 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 | + | |
| 102 | 164 | /// The topbar's signed-in identity: the display name, opening on hover or |
| 103 | 165 | /// focus onto details (name, address, role) and sign-out. Shared by every |
| 104 | 166 | /// 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 { | ||
| 114 | 114 | 8, |
| 115 | 115 | FeedPage::Newest, |
| 116 | 116 | Dir::Newest, |
| 117 | - &ActivityFilter { actor: Some(person.id.clone()), ..Default::default() }, | |
| 117 | + &ActivityFilter { | |
| 118 | + actor: Some(person.id.clone()), | |
| 119 | + ..Default::default() | |
| 120 | + }, | |
| 118 | 121 | ) |
| 119 | 122 | .await?; |
| 120 | 123 | |
| @@ -130,7 +133,13 @@ async fn people_page(cx: &Cx) -> Result { | ||
| 130 | 133 | <main class="people-shell"> |
| 131 | 134 | <section class="panel person-card"> |
| 132 | 135 | <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 | + } | |
| 134 | 143 | <div class="person-heading"> |
| 135 | 144 | <h2 class="person-name">(person.display_name.clone())</h2> |
| 136 | 145 | <div class="person-marks"> |
| @@ -216,5 +225,7 @@ async fn people_page(cx: &Cx) -> Result { | ||
| 216 | 225 | </main> |
| 217 | 226 | |
| 218 | 227 | (crate::layout::escape_script(cx).await?) |
| 228 | + (crate::detail::escape_closes(cx).await?) | |
| 229 | + (crate::layout::avatar_script(cx).await?) | |
| 219 | 230 | } |
| 220 | 231 | } |
crates/iz-web/src/settings.rsmodified+14 -67
| @@ -957,7 +957,10 @@ async fn send_message( | ||
| 957 | 957 | }; |
| 958 | 958 | let subject = input.subject.trim(); |
| 959 | 959 | 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 | + )); | |
| 961 | 964 | } |
| 962 | 965 | let body = input.body.trim(); |
| 963 | 966 | if body.is_empty() { |
| @@ -974,7 +977,12 @@ async fn send_message( | ||
| 974 | 977 | } else { |
| 975 | 978 | match members.into_iter().find(|member| member.id == input.to) { |
| 976 | 979 | 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 | + } | |
| 978 | 986 | } |
| 979 | 987 | }; |
| 980 | 988 | let now = time::OffsetDateTime::now_utc(); |
| @@ -1193,9 +1201,7 @@ fn is_origin(value: &str) -> bool { | ||
| 1193 | 1201 | return false; |
| 1194 | 1202 | }; |
| 1195 | 1203 | 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) | |
| 1199 | 1205 | } |
| 1200 | 1206 | |
| 1201 | 1207 | /// 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 { | ||
| 1316 | 1322 | None |
| 1317 | 1323 | }; |
| 1318 | 1324 | 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?; | |
| 1320 | 1327 | (Some((attachment, photo, batch, reminder)), types) |
| 1321 | 1328 | } else { |
| 1322 | 1329 | (None, Vec::new()) |
| @@ -1954,66 +1961,6 @@ async fn settings_page(cx: &Cx) -> Result { | ||
| 1954 | 1961 | (crate::dropdown::dropdown_script(cx).await?) |
| 1955 | 1962 | (crate::layout::escape_script(cx).await?) |
| 1956 | 1963 | (crate::detail::escape_closes(cx).await?) |
| 1957 | - (avatar_script(cx).await?) | |
| 1964 | + (crate::layout::avatar_script(cx).await?) | |
| 1958 | 1965 | } |
| 1959 | 1966 | } |
| 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) { | ||
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | |
| 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 | + | |
| 214 | 239 | await browser.close(); |
| 215 | 240 | |
| 216 | 241 | note(`page errors ${errors.length ? errors.join(' | ') : 'none'}`); |
style/main.scssmodified+12 -8
| @@ -1064,24 +1064,28 @@ img.avatar { | ||
| 1064 | 1064 | gap: 14px; |
| 1065 | 1065 | } |
| 1066 | 1066 | |
| 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. | |
| 1069 | 1070 | .avatar-upload, |
| 1070 | 1071 | .avatar-view { |
| 1071 | 1072 | position: relative; |
| 1072 | 1073 | flex: none; |
| 1073 | 1074 | cursor: pointer; |
| 1074 | 1075 | |
| 1075 | - .avatar { | |
| 1076 | - width: 64px; | |
| 1077 | - height: 64px; | |
| 1078 | - font-size: 20px; | |
| 1079 | - } | |
| 1080 | - | |
| 1081 | 1076 | // The name tooltip has no job on your own picture. |
| 1082 | 1077 | .avatar[data-name]:hover::after { content: none; } |
| 1083 | 1078 | } |
| 1084 | 1079 | |
| 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 | + | |
| 1085 | 1089 | // The trigger is the label's box with a button's chrome stripped. |
| 1086 | 1090 | .avatar-view { |
| 1087 | 1091 | appearance: none; |