diff --git a/crates/iz-web/src/detail.rs b/crates/iz-web/src/detail.rs index 576fa54..303cd30 100644 --- a/crates/iz-web/src/detail.rs +++ b/crates/iz-web/src/detail.rs @@ -1149,13 +1149,18 @@ pub(crate) mod glyph { /// delete confirm (`confirm=delete` in URL) → open edit popovers → modal /// itself — one resolver at priority 90 on `window.__izEsc` (table on /// `layout.rs`'s `escape_manager_script`); an open datepick popover returns -/// false, leaving it to `board.rs`'s priority-100 resolver. Closing never +/// false, leaving it to `board.rs`'s priority-100 resolver. The settings +/// page emits it too: its profile photo viewer is a `.viewer-scrim`, and +/// this is the one resolver that closes one — its other branches find no +/// confirm, no edit toggles and no modal there and fall through. +/// +/// Closing never /// navigates: `layout.rs`'s `__izCloseViewer`/`__izCloseModal` drop /// the overlay's DOM and rewrite the URL, the board underneath is already /// rendered. Focused native media controls swallow `Escape` before the page /// ever sees the key, so focus landing on the viewer's audio/video is moved /// straight back to the panel. -async fn escape_closes(cx: &Cx) -> Result { +pub(crate) async fn escape_closes(cx: &Cx) -> Result { use topcoat::view::Unescaped; const JS: &str = "\ (function () { \ diff --git a/crates/iz-web/src/i18n.rs b/crates/iz-web/src/i18n.rs index 82103bb..0d700d0 100644 --- a/crates/iz-web/src/i18n.rs +++ b/crates/iz-web/src/i18n.rs @@ -121,6 +121,7 @@ pub enum Key { // settings.rs YourProfile, + Change, Remove, DisplayNameLabel, EmailLabel, @@ -573,6 +574,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { (YourProfile, Tr) => "Profilin", (Remove, En) => "Remove", (Remove, Tr) => "Kaldır", + (Change, En) => "Change", + (Change, Tr) => "Değiştir", (DisplayNameLabel, En) => "DISPLAY NAME", (DisplayNameLabel, Tr) => "GÖRÜNEN AD", (EmailLabel, En) => "EMAIL", diff --git a/crates/iz-web/src/settings.rs b/crates/iz-web/src/settings.rs index 5d93cac..ebd2e1d 100644 --- a/crates/iz-web/src/settings.rs +++ b/crates/iz-web/src/settings.rs @@ -1273,16 +1273,26 @@ async fn settings_page(cx: &Cx) -> Result {
- if user.has_photo { + + + + } else { + } if let Some(refusal) = &photo_refusal { (refusal.message_in(lang)) @@ -1767,5 +1777,67 @@ 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?) } } + +/// 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 new file mode 100644 index 0000000..abbe145 --- /dev/null +++ b/crates/iz-web/tests/browser/photo.mjs @@ -0,0 +1,197 @@ +// The profile photo's overlay: with a photo set, clicking the avatar on the +// settings profile section opens the picture in the file viewer's chrome, +// and the picker moves to the Change button. `tests/http.rs` can assert the +// served markup; only a browser shows the client-built overlay opening, the +// three ways it closes (Escape, the X, the scrim), and the relocated input +// still autosubmitting — the class where the upload quietly did nothing. +// +// Wants the server run.sh leaves behind: the workspace already claimed +// (soft-nav claims it), so this signs in — but it claims too, so the +// script runs standalone as well: +// +// node crates/iz-web/tests/browser/photo.mjs http://127.0.0.1:7791 +// +// Playwright lives outside the repo, exactly as soft-nav.mjs says. +const { chromium } = await import(process.env.IZ_PLAYWRIGHT || 'playwright'); +const zlib = await import('node:zlib'); +const fs = await import('node:fs'); +const os = await import('node:os'); +const path = await import('node:path'); + +const base = process.argv[2] || 'http://127.0.0.1:7791'; +const shots = process.env.SHOT_DIR || '.'; +const failures = []; +const note = (line) => console.log(line); + +// A real image, generated here so the check carries no fixture: the upload +// sniffs bytes, and the overlay assertion reads the served naturalWidth. +const W = 240; +const H = 160; +function makePng() { + const table = []; + for (let n = 0; n < 256; n++) { + let c = n; + for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1; + table[n] = c >>> 0; + } + const crc32 = (buf) => { + let c = 0xffffffff; + for (const b of buf) c = table[(c ^ b) & 0xff] ^ (c >>> 8); + return (c ^ 0xffffffff) >>> 0; + }; + const chunk = (tag, data) => { + const t = Buffer.from(tag, 'ascii'); + const len = Buffer.alloc(4); + len.writeUInt32BE(data.length); + const crc = Buffer.alloc(4); + crc.writeUInt32BE(crc32(Buffer.concat([t, data]))); + return Buffer.concat([len, t, data, crc]); + }; + const ihdr = Buffer.alloc(13); + ihdr.writeUInt32BE(W, 0); + ihdr.writeUInt32BE(H, 4); + ihdr[8] = 8; // bit depth + ihdr[9] = 2; // truecolor + const rows = Buffer.alloc(H * (1 + W * 3)); + let o = 0; + for (let y = 0; y < H; y++) { + rows[o++] = 0; + for (let x = 0; x < W; x++) { + rows[o++] = Math.floor((x * 255) / (W - 1)); + rows[o++] = Math.floor((y * 255) / (H - 1)); + rows[o++] = 140; + } + } + return Buffer.concat([ + Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), + chunk('IHDR', ihdr), + chunk('IDAT', zlib.deflateSync(rows)), + chunk('IEND', Buffer.alloc(0)), + ]); +} +const photoPath = path.join(os.tmpdir(), 'iz-photo-check.png'); +fs.writeFileSync(photoPath, makePng()); + +const browser = await chromium.launch(); +const ctx = await browser.newContext(); +const page = await ctx.newPage(); +const errors = []; +page.on('pageerror', (e) => errors.push('PE ' + e.message)); +page.on('console', (m) => { + if (m.type() === 'error') errors.push('CON ' + m.text()); +}); + +// Claimed by soft-nav when run from run.sh, unclaimed standalone — either +// form signs the same admin in. +await page.goto(base + '/', { waitUntil: 'networkidle' }); +if (await page.locator('input[name="display_name"]').count()) { + await page.fill('input[name="display_name"]', 'Ada Lovelace'); + await page.fill('input[name="email"]', 'ada@iz.sh'); + await page.fill('input[name="password"]', 'correct horse battery staple'); + await Promise.all([page.waitForLoadState('networkidle'), page.click('button[type="submit"]')]); +} else { + await page.fill('input[name="email"]', 'ada@iz.sh'); + await page.fill('input[name="password"]', 'correct horse battery staple'); + await Promise.all([page.waitForLoadState('networkidle'), page.click('button[type="submit"]')]); +} + +await page.goto(base + '/settings', { waitUntil: 'networkidle' }); +if (!(await page.locator('.identity-row').count())) { + failures.push(`settings profile section never rendered at ${page.url()}`); +} + +// No photo yet: the label is the picker. Setting a file on its input must +// autosubmit and swap in the viewer trigger — the relocation regression is +// exactly an upload that silently does nothing. +if (!failures.length) { + await page.setInputFiles('input.file-upload-input', photoPath); + const swapped = await page + .waitForFunction(() => document.querySelector('button.avatar-view'), { timeout: 5000 }) + .then(() => true) + .catch(() => false); + if (!swapped) failures.push('the upload never swapped in the viewer trigger'); +} + +// The trigger opens the overlay; the picture must be the served photo, not +// a placeholder. Screenshot stands as the alignment check. +async function openViewer(label) { + await page.click('.avatar-view'); + const open = await page + .waitForFunction( + () => { + const m = document.querySelector('.viewer-scrim .viewer-media'); + return m && m.complete && m.naturalWidth > 0; + }, + { timeout: 5000 }, + ) + .then(() => true) + .catch(() => false); + if (!open) { + failures.push(`${label}: the overlay never opened with the photo`); + return false; + } + const src = await page.locator('.viewer-scrim .viewer-media').getAttribute('src'); + if (!src || !src.includes('/photo/')) failures.push(`${label}: overlay image src is '${src}'`); + const width = await page.evaluate(() => document.querySelector('.viewer-scrim .viewer-media').naturalWidth); + if (width !== W) failures.push(`${label}: overlay serves naturalWidth ${width}, expected ${W}`); + return true; +} +async function viewerGone(label) { + const gone = await page + .waitForFunction(() => !document.querySelector('.viewer-scrim'), { timeout: 5000 }) + .then(() => true) + .catch(() => false); + if (!gone) failures.push(`${label}: the overlay never closed`); +} + +if (!failures.length) { + if (await openViewer('escape')) { + await page.screenshot({ path: `${shots}/photo-viewer.png` }); + await page.keyboard.press('Escape'); + await viewerGone('escape'); + } + if (await openViewer('close-anchor')) { + await page.click('.viewer-close'); + await viewerGone('close-anchor'); + } + if (await openViewer('scrim')) { + await page.mouse.click(4, 4); + await viewerGone('scrim'); + } +} + +// Change owns the picker now: the click must surface the chooser, and a +// chosen file must save through the same autosubmit the label used. +if (!failures.length) { + if (!(await page.locator('[data-avatar-change]').count())) { + failures.push('no Change button next to the photo'); + } else { + const [chooser] = await Promise.all([ + page.waitForEvent('filechooser', { timeout: 5000 }).catch(() => null), + page.click('[data-avatar-change]'), + ]); + if (!chooser) { + failures.push('the Change click never opened the picker'); + } else { + await chooser.setFiles(photoPath); + const saved = await page + .waitForFunction(() => document.querySelector('.identity-row .field-note'), { timeout: 5000 }) + .then(() => true) + .catch(() => false); + if (!saved) failures.push('the Change upload never confirmed the save'); + if (await page.locator('.identity-row .field-error').count()) { + failures.push(`the Change upload drew a refusal: ${await page.locator('.identity-row .field-error').textContent()}`); + } + } + } +} + +await browser.close(); + +note(`page errors ${errors.length ? errors.join(' | ') : 'none'}`); +if (errors.length) failures.push(`page errors: ${errors.join(' | ')}`); +if (failures.length) { + for (const f of failures) note('FAIL ' + f); + process.exit(1); +} +note('PASS the photo overlay opens on the avatar click, closes all three ways, and Change saves through the picker'); diff --git a/crates/iz-web/tests/browser/run.sh b/crates/iz-web/tests/browser/run.sh index 2c2c684..8226ce9 100755 --- a/crates/iz-web/tests/browser/run.sh +++ b/crates/iz-web/tests/browser/run.sh @@ -71,3 +71,7 @@ SHOT_DIR="$shots" node "$repo/crates/iz-web/tests/browser/soft-nav.mjs" "http:// # workspace, so this one signs the same admin in; it claims too when it # runs standalone. Either script failing fails the run. SHOT_DIR="$shots" node "$repo/crates/iz-web/tests/browser/moment.mjs" "http://127.0.0.1:$port" + +# The profile photo overlay's own pass, same workspace and admin as the +# moment field. Either script failing fails the run. +SHOT_DIR="$shots" node "$repo/crates/iz-web/tests/browser/photo.mjs" "http://127.0.0.1:$port" diff --git a/style/main.scss b/style/main.scss index 49c44c7..e4f1039 100644 --- a/style/main.scss +++ b/style/main.scss @@ -1054,16 +1054,20 @@ img.avatar { display: block; } -// The avatar leads the profile panel and is itself the upload control: the -// file input rides its `form` attribute to a hidden sibling form, so nothing -// nests inside the profile form. +// The avatar leads the profile panel. Without a photo it is itself the +// upload control — the file input rides its `form` attribute to a hidden +// sibling form, so nothing nests inside the profile form. With one, the +// click opens the photo viewer and a Change button owns the picker instead. .identity-row { display: flex; align-items: center; gap: 14px; } -.avatar-upload { +// The two faces of the 64px profile picture box: the picker label and, once +// a photo exists, the viewer trigger. +.avatar-upload, +.avatar-view { position: relative; flex: none; cursor: pointer; @@ -1074,6 +1078,19 @@ img.avatar { font-size: 20px; } + // The name tooltip has no job on your own picture. + .avatar[data-name]:hover::after { content: none; } +} + +// The trigger is the label's box with a button's chrome stripped. +.avatar-view { + appearance: none; + background: none; + border: none; + padding: 0; +} + +.avatar-upload { // The upload affordance: a veil and a plus over the picture, on hover or // keyboard focus only. &::after { @@ -1095,9 +1112,6 @@ img.avatar { &:hover::after, &:has(.file-upload-input:focus-visible)::after { opacity: 1; } - - // The name tooltip has no job on your own picture. - .avatar[data-name]:hover::after { content: none; } } // -- the card context menu ---------------------------------------------------