forge
Explore
Log in

Don't you dare go Hollow

The profile photo opens in the viewer chrome, Change owns the picker

Browse files at this commit

79ce4668dffdb4b84ace702bbf79408a444e2b48Ahmet Kaan GümüşParent: 7326831
With a photo set, the avatar click on the settings profile section opens
the picture in the file viewer's own frame — scrim, Escape chain and the
stretched close layer all reused, nothing rewired — and a Change button
beside Remove hands the click to the same hidden input the label used.
Without a photo the label picker is untouched. A third browser pass joins
run.sh: open, all three closes, and a save through the picker.
crates/iz-web/src/detail.rsmodified+7 -2
@@ -1149,13 +1149,18 @@ pub(crate) mod glyph {
1149 /// delete confirm (`confirm=delete` in URL) → open edit popovers → modal1149 /// delete confirm (`confirm=delete` in URL) → open edit popovers → modal
1150 /// itself — one resolver at priority 90 on `window.__izEsc` (table on1150 /// itself — one resolver at priority 90 on `window.__izEsc` (table on
1151 /// `layout.rs`'s `escape_manager_script`); an open datepick popover returns1151 /// `layout.rs`'s `escape_manager_script`); an open datepick popover returns
1152-/// false, leaving it to `board.rs`'s priority-100 resolver. Closing never1152+/// false, leaving it to `board.rs`'s priority-100 resolver. The settings
1153+/// page emits it too: its profile photo viewer is a `.viewer-scrim`, and
1154+/// this is the one resolver that closes one — its other branches find no
1155+/// confirm, no edit toggles and no modal there and fall through.
1156+///
1157+/// Closing never
1153 /// navigates: `layout.rs`'s `__izCloseViewer`/`__izCloseModal` drop1158 /// navigates: `layout.rs`'s `__izCloseViewer`/`__izCloseModal` drop
1154 /// the overlay's DOM and rewrite the URL, the board underneath is already1159 /// the overlay's DOM and rewrite the URL, the board underneath is already
1155 /// rendered. Focused native media controls swallow `Escape` before the page1160 /// rendered. Focused native media controls swallow `Escape` before the page
1156 /// ever sees the key, so focus landing on the viewer's audio/video is moved1161 /// ever sees the key, so focus landing on the viewer's audio/video is moved
1157 /// straight back to the panel.1162 /// straight back to the panel.
1158-async fn escape_closes(cx: &Cx) -> Result {1163+pub(crate) async fn escape_closes(cx: &Cx) -> Result {
1159 use topcoat::view::Unescaped;1164 use topcoat::view::Unescaped;
1160 const JS: &str = "\1165 const JS: &str = "\
1161 (function () { \1166 (function () { \
crates/iz-web/src/i18n.rsmodified+3 -0
@@ -121,6 +121,7 @@ pub enum Key {
121 121
122 // settings.rs122 // settings.rs
123 YourProfile,123 YourProfile,
124+ Change,
124 Remove,125 Remove,
125 DisplayNameLabel,126 DisplayNameLabel,
126 EmailLabel,127 EmailLabel,
@@ -573,6 +574,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
573 (YourProfile, Tr) => "Profilin",574 (YourProfile, Tr) => "Profilin",
574 (Remove, En) => "Remove",575 (Remove, En) => "Remove",
575 (Remove, Tr) => "Kaldır",576 (Remove, Tr) => "Kaldır",
577+ (Change, En) => "Change",
578+ (Change, Tr) => "Değiştir",
576 (DisplayNameLabel, En) => "DISPLAY NAME",579 (DisplayNameLabel, En) => "DISPLAY NAME",
577 (DisplayNameLabel, Tr) => "GÖRÜNEN AD",580 (DisplayNameLabel, Tr) => "GÖRÜNEN AD",
578 (EmailLabel, En) => "EMAIL",581 (EmailLabel, En) => "EMAIL",
crates/iz-web/src/settings.rsmodified+80 -8
@@ -1273,16 +1273,26 @@ async fn settings_page(cx: &Cx) -> Result {
1273 </div>1273 </div>
1274 <form method="post" action="/api/save_profile" class="panel-body">1274 <form method="post" action="/api/save_profile" class="panel-body">
1275 <div class="identity-row">1275 <div class="identity-row">
1276- <label class="avatar-upload">
1277- (crate::layout::avatar(cx, &iz_core::board::Person {
1278- id: user.id.clone(),
1279- display_name: user.display_name.clone(),
1280- has_photo: user.has_photo,
1281- }, "avatar-lg").await?)
1282- <input class="file-upload-input" type="file" name="file" accept="image/*" data-autosubmit="" form="photo-form">
1283- </label>
1284 if user.has_photo {1276 if user.has_photo {
1277+ <button class="avatar-view" type="button" data-close-label=(t(lang, Key::Close))>
1278+ (crate::layout::avatar(cx, &iz_core::board::Person {
1279+ id: user.id.clone(),
1280+ display_name: user.display_name.clone(),
1281+ has_photo: user.has_photo,
1282+ }, "avatar-lg").await?)
1283+ </button>
1284+ <button class="quiet" type="button" data-avatar-change="">(t(lang, Key::Change))</button>
1285 <button class="quiet" type="submit" form="photo-remove-form">(t(lang, Key::Remove))</button>1285 <button class="quiet" type="submit" form="photo-remove-form">(t(lang, Key::Remove))</button>
1286+ <input class="file-upload-input" type="file" name="file" accept="image/*" data-autosubmit="" form="photo-form">
1287+ } else {
1288+ <label class="avatar-upload">
1289+ (crate::layout::avatar(cx, &iz_core::board::Person {
1290+ id: user.id.clone(),
1291+ display_name: user.display_name.clone(),
1292+ has_photo: user.has_photo,
1293+ }, "avatar-lg").await?)
1294+ <input class="file-upload-input" type="file" name="file" accept="image/*" data-autosubmit="" form="photo-form">
1295+ </label>
1286 }1296 }
1287 if let Some(refusal) = &photo_refusal {1297 if let Some(refusal) = &photo_refusal {
1288 <span class="field-error">(refusal.message_in(lang))</span>1298 <span class="field-error">(refusal.message_in(lang))</span>
@@ -1767,5 +1777,67 @@ async fn settings_page(cx: &Cx) -> Result {
1767 </div>1777 </div>
1768 (crate::dropdown::dropdown_script(cx).await?)1778 (crate::dropdown::dropdown_script(cx).await?)
1769 (crate::layout::escape_script(cx).await?)1779 (crate::layout::escape_script(cx).await?)
1780+ (crate::detail::escape_closes(cx).await?)
1781+ (avatar_script(cx).await?)
1770 }1782 }
1771 }1783 }
1784+
1785+/// The profile photo's overlay: with a photo set, the avatar click opens the
1786+/// file viewer's chrome (`detail.rs`'s `file_viewer_modal` — the
1787+/// `.modal-scrim.viewer-scrim` scrim and the `.modal.viewer` panel around a
1788+/// `.viewer-media` image) around the same `/photo/{id}?v=` URL the avatar
1789+/// reads. Built here because the overlay has no server state behind it — no
1790+/// route, no query parameter, nothing to render — so it is client-built and
1791+/// `__izAdded`'d. Closing is not wired here at all: the stretched
1792+/// `.viewer-close` anchor and the scrim click are the global handlers in
1793+/// `layout.rs`'s soft-nav script, and Escape is `detail.rs`'s
1794+/// `escape_closes` (priority 90), emitted alongside this script. The picture
1795+/// is read off the avatar's own `<img>` at click time, stamp included, so a
1796+/// fresh upload is the fresh bytes. Change hands the click to the hidden
1797+/// file input, whose change the shared autosubmit listener in `layout.rs`
1798+/// posts as the photo form.
1799+async fn avatar_script(cx: &Cx) -> Result {
1800+ use topcoat::view::Unescaped;
1801+ const JS: &str = "\
1802+ (function () { \
1803+ if (window.__izAvatar) { return; } \
1804+ window.__izAvatar = true; \
1805+ document.addEventListener('click', function (e) { \
1806+ var view = e.target.closest ? e.target.closest('.avatar-view') : null; \
1807+ if (view) { \
1808+ var img = view.querySelector('img.avatar'); \
1809+ if (!img || document.querySelector('.viewer-scrim')) { return; } \
1810+ var scrim = document.createElement('div'); \
1811+ scrim.className = 'modal-scrim viewer-scrim'; \
1812+ var close = document.createElement('a'); \
1813+ close.className = 'viewer-close'; \
1814+ close.href = window.location.href; \
1815+ var label = view.getAttribute('data-close-label'); \
1816+ if (label) { close.setAttribute('aria-label', label); } \
1817+ var media = document.createElement('img'); \
1818+ media.className = 'viewer-media'; \
1819+ media.src = img.src; \
1820+ media.alt = img.alt; \
1821+ var body = document.createElement('div'); \
1822+ body.className = 'viewer-body'; \
1823+ body.appendChild(media); \
1824+ var box = document.createElement('div'); \
1825+ box.className = 'modal viewer'; \
1826+ box.tabIndex = -1; \
1827+ box.appendChild(body); \
1828+ scrim.appendChild(close); \
1829+ scrim.appendChild(box); \
1830+ document.body.appendChild(window.__izAdded(scrim)); \
1831+ box.focus(); \
1832+ return; \
1833+ } \
1834+ var change = e.target.closest ? e.target.closest('[data-avatar-change]') : null; \
1835+ if (change) { \
1836+ var row = change.closest('.identity-row'); \
1837+ var input = row ? row.querySelector('.file-upload-input') : null; \
1838+ if (input) { input.click(); } \
1839+ } \
1840+ }, true); \
1841+ })();";
1842+ view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }
1843+}
crates/iz-web/tests/browser/photo.mjsadded+197 -0
@@ -0,0 +1,197 @@
1+// The profile photo's overlay: with a photo set, clicking the avatar on the
2+// settings profile section opens the picture in the file viewer's chrome,
3+// and the picker moves to the Change button. `tests/http.rs` can assert the
4+// served markup; only a browser shows the client-built overlay opening, the
5+// three ways it closes (Escape, the X, the scrim), and the relocated input
6+// still autosubmitting — the class where the upload quietly did nothing.
7+//
8+// Wants the server run.sh leaves behind: the workspace already claimed
9+// (soft-nav claims it), so this signs in — but it claims too, so the
10+// script runs standalone as well:
11+//
12+// node crates/iz-web/tests/browser/photo.mjs http://127.0.0.1:7791
13+//
14+// Playwright lives outside the repo, exactly as soft-nav.mjs says.
15+const { chromium } = await import(process.env.IZ_PLAYWRIGHT || 'playwright');
16+const zlib = await import('node:zlib');
17+const fs = await import('node:fs');
18+const os = await import('node:os');
19+const path = await import('node:path');
20+
21+const base = process.argv[2] || 'http://127.0.0.1:7791';
22+const shots = process.env.SHOT_DIR || '.';
23+const failures = [];
24+const note = (line) => console.log(line);
25+
26+// A real image, generated here so the check carries no fixture: the upload
27+// sniffs bytes, and the overlay assertion reads the served naturalWidth.
28+const W = 240;
29+const H = 160;
30+function makePng() {
31+ const table = [];
32+ for (let n = 0; n < 256; n++) {
33+ let c = n;
34+ for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
35+ table[n] = c >>> 0;
36+ }
37+ const crc32 = (buf) => {
38+ let c = 0xffffffff;
39+ for (const b of buf) c = table[(c ^ b) & 0xff] ^ (c >>> 8);
40+ return (c ^ 0xffffffff) >>> 0;
41+ };
42+ const chunk = (tag, data) => {
43+ const t = Buffer.from(tag, 'ascii');
44+ const len = Buffer.alloc(4);
45+ len.writeUInt32BE(data.length);
46+ const crc = Buffer.alloc(4);
47+ crc.writeUInt32BE(crc32(Buffer.concat([t, data])));
48+ return Buffer.concat([len, t, data, crc]);
49+ };
50+ const ihdr = Buffer.alloc(13);
51+ ihdr.writeUInt32BE(W, 0);
52+ ihdr.writeUInt32BE(H, 4);
53+ ihdr[8] = 8; // bit depth
54+ ihdr[9] = 2; // truecolor
55+ const rows = Buffer.alloc(H * (1 + W * 3));
56+ let o = 0;
57+ for (let y = 0; y < H; y++) {
58+ rows[o++] = 0;
59+ for (let x = 0; x < W; x++) {
60+ rows[o++] = Math.floor((x * 255) / (W - 1));
61+ rows[o++] = Math.floor((y * 255) / (H - 1));
62+ rows[o++] = 140;
63+ }
64+ }
65+ return Buffer.concat([
66+ Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),
67+ chunk('IHDR', ihdr),
68+ chunk('IDAT', zlib.deflateSync(rows)),
69+ chunk('IEND', Buffer.alloc(0)),
70+ ]);
71+}
72+const photoPath = path.join(os.tmpdir(), 'iz-photo-check.png');
73+fs.writeFileSync(photoPath, makePng());
74+
75+const browser = await chromium.launch();
76+const ctx = await browser.newContext();
77+const page = await ctx.newPage();
78+const errors = [];
79+page.on('pageerror', (e) => errors.push('PE ' + e.message));
80+page.on('console', (m) => {
81+ if (m.type() === 'error') errors.push('CON ' + m.text());
82+});
83+
84+// Claimed by soft-nav when run from run.sh, unclaimed standalone — either
85+// form signs the same admin in.
86+await page.goto(base + '/', { waitUntil: 'networkidle' });
87+if (await page.locator('input[name="display_name"]').count()) {
88+ await page.fill('input[name="display_name"]', 'Ada Lovelace');
89+ await page.fill('input[name="email"]', 'ada@iz.sh');
90+ await page.fill('input[name="password"]', 'correct horse battery staple');
91+ await Promise.all([page.waitForLoadState('networkidle'), page.click('button[type="submit"]')]);
92+} else {
93+ await page.fill('input[name="email"]', 'ada@iz.sh');
94+ await page.fill('input[name="password"]', 'correct horse battery staple');
95+ await Promise.all([page.waitForLoadState('networkidle'), page.click('button[type="submit"]')]);
96+}
97+
98+await page.goto(base + '/settings', { waitUntil: 'networkidle' });
99+if (!(await page.locator('.identity-row').count())) {
100+ failures.push(`settings profile section never rendered at ${page.url()}`);
101+}
102+
103+// No photo yet: the label is the picker. Setting a file on its input must
104+// autosubmit and swap in the viewer trigger — the relocation regression is
105+// exactly an upload that silently does nothing.
106+if (!failures.length) {
107+ await page.setInputFiles('input.file-upload-input', photoPath);
108+ const swapped = await page
109+ .waitForFunction(() => document.querySelector('button.avatar-view'), { timeout: 5000 })
110+ .then(() => true)
111+ .catch(() => false);
112+ if (!swapped) failures.push('the upload never swapped in the viewer trigger');
113+}
114+
115+// The trigger opens the overlay; the picture must be the served photo, not
116+// a placeholder. Screenshot stands as the alignment check.
117+async function openViewer(label) {
118+ await page.click('.avatar-view');
119+ const open = await page
120+ .waitForFunction(
121+ () => {
122+ const m = document.querySelector('.viewer-scrim .viewer-media');
123+ return m && m.complete && m.naturalWidth > 0;
124+ },
125+ { timeout: 5000 },
126+ )
127+ .then(() => true)
128+ .catch(() => false);
129+ if (!open) {
130+ failures.push(`${label}: the overlay never opened with the photo`);
131+ return false;
132+ }
133+ const src = await page.locator('.viewer-scrim .viewer-media').getAttribute('src');
134+ if (!src || !src.includes('/photo/')) failures.push(`${label}: overlay image src is '${src}'`);
135+ const width = await page.evaluate(() => document.querySelector('.viewer-scrim .viewer-media').naturalWidth);
136+ if (width !== W) failures.push(`${label}: overlay serves naturalWidth ${width}, expected ${W}`);
137+ return true;
138+}
139+async function viewerGone(label) {
140+ const gone = await page
141+ .waitForFunction(() => !document.querySelector('.viewer-scrim'), { timeout: 5000 })
142+ .then(() => true)
143+ .catch(() => false);
144+ if (!gone) failures.push(`${label}: the overlay never closed`);
145+}
146+
147+if (!failures.length) {
148+ if (await openViewer('escape')) {
149+ await page.screenshot({ path: `${shots}/photo-viewer.png` });
150+ await page.keyboard.press('Escape');
151+ await viewerGone('escape');
152+ }
153+ if (await openViewer('close-anchor')) {
154+ await page.click('.viewer-close');
155+ await viewerGone('close-anchor');
156+ }
157+ if (await openViewer('scrim')) {
158+ await page.mouse.click(4, 4);
159+ await viewerGone('scrim');
160+ }
161+}
162+
163+// Change owns the picker now: the click must surface the chooser, and a
164+// chosen file must save through the same autosubmit the label used.
165+if (!failures.length) {
166+ if (!(await page.locator('[data-avatar-change]').count())) {
167+ failures.push('no Change button next to the photo');
168+ } else {
169+ const [chooser] = await Promise.all([
170+ page.waitForEvent('filechooser', { timeout: 5000 }).catch(() => null),
171+ page.click('[data-avatar-change]'),
172+ ]);
173+ if (!chooser) {
174+ failures.push('the Change click never opened the picker');
175+ } else {
176+ await chooser.setFiles(photoPath);
177+ const saved = await page
178+ .waitForFunction(() => document.querySelector('.identity-row .field-note'), { timeout: 5000 })
179+ .then(() => true)
180+ .catch(() => false);
181+ if (!saved) failures.push('the Change upload never confirmed the save');
182+ if (await page.locator('.identity-row .field-error').count()) {
183+ failures.push(`the Change upload drew a refusal: ${await page.locator('.identity-row .field-error').textContent()}`);
184+ }
185+ }
186+ }
187+}
188+
189+await browser.close();
190+
191+note(`page errors ${errors.length ? errors.join(' | ') : 'none'}`);
192+if (errors.length) failures.push(`page errors: ${errors.join(' | ')}`);
193+if (failures.length) {
194+ for (const f of failures) note('FAIL ' + f);
195+ process.exit(1);
196+}
197+note('PASS the photo overlay opens on the avatar click, closes all three ways, and Change saves through the picker');
crates/iz-web/tests/browser/run.shmodified+4 -0
@@ -71,3 +71,7 @@ SHOT_DIR="$shots" node "$repo/crates/iz-web/tests/browser/soft-nav.mjs" "http://
71 # workspace, so this one signs the same admin in; it claims too when it71 # workspace, so this one signs the same admin in; it claims too when it
72 # runs standalone. Either script failing fails the run.72 # runs standalone. Either script failing fails the run.
73 SHOT_DIR="$shots" node "$repo/crates/iz-web/tests/browser/moment.mjs" "http://127.0.0.1:$port"73 SHOT_DIR="$shots" node "$repo/crates/iz-web/tests/browser/moment.mjs" "http://127.0.0.1:$port"
74+
75+# The profile photo overlay's own pass, same workspace and admin as the
76+# moment field. Either script failing fails the run.
77+SHOT_DIR="$shots" node "$repo/crates/iz-web/tests/browser/photo.mjs" "http://127.0.0.1:$port"
style/main.scssmodified+21 -7
@@ -1054,16 +1054,20 @@ img.avatar {
1054 display: block;1054 display: block;
1055 }1055 }
1056 1056
1057-// The avatar leads the profile panel and is itself the upload control: the1057+// The avatar leads the profile panel. Without a photo it is itself the
1058-// file input rides its `form` attribute to a hidden sibling form, so nothing1058+// upload control — the file input rides its `form` attribute to a hidden
1059-// nests inside the profile form.1059+// sibling form, so nothing nests inside the profile form. With one, the
1060+// click opens the photo viewer and a Change button owns the picker instead.
1060 .identity-row {1061 .identity-row {
1061 display: flex;1062 display: flex;
1062 align-items: center;1063 align-items: center;
1063 gap: 14px;1064 gap: 14px;
1064 }1065 }
1065 1066
1066-.avatar-upload {1067+// The two faces of the 64px profile picture box: the picker label and, once
1068+// a photo exists, the viewer trigger.
1069+.avatar-upload,
1070+.avatar-view {
1067 position: relative;1071 position: relative;
1068 flex: none;1072 flex: none;
1069 cursor: pointer;1073 cursor: pointer;
@@ -1074,6 +1078,19 @@ img.avatar {
1074 font-size: 20px;1078 font-size: 20px;
1075 }1079 }
1076 1080
1081+ // The name tooltip has no job on your own picture.
1082+ .avatar[data-name]:hover::after { content: none; }
1083+}
1084+
1085+// The trigger is the label's box with a button's chrome stripped.
1086+.avatar-view {
1087+ appearance: none;
1088+ background: none;
1089+ border: none;
1090+ padding: 0;
1091+}
1092+
1093+.avatar-upload {
1077 // The upload affordance: a veil and a plus over the picture, on hover or1094 // The upload affordance: a veil and a plus over the picture, on hover or
1078 // keyboard focus only.1095 // keyboard focus only.
1079 &::after {1096 &::after {
@@ -1095,9 +1112,6 @@ img.avatar {
1095 1112
1096 &:hover::after,1113 &:hover::after,
1097 &:has(.file-upload-input:focus-visible)::after { opacity: 1; }1114 &:has(.file-upload-input:focus-visible)::after { opacity: 1; }
1098-
1099- // The name tooltip has no job on your own picture.
1100- .avatar[data-name]:hover::after { content: none; }
1101 }1115 }
1102 1116
1103 // -- the card context menu ---------------------------------------------------1117 // -- the card context menu ---------------------------------------------------