From f09955969e9a995e9ad76324eea0d12ac99d00b5 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 08:13:54 +0300 Subject: [PATCH] Avatar is the picker; photos autosubmit; the face opens a viewer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit iz's identity row, verbatim in behavior: no Add photo button (the no-photo tile is the picker label, with iz's hover veil — a plus over the picture on hover or focus), no Save button (a data-autosubmit input posts its form on change — choosing a file IS the upload), and a click on a photo face opens a viewer scrim around the same /photo URL, on the landing and the public profile alike. It is im's first client script: one small delegated listener set in layout.rs, emitted by the two pages that draw a clickable face. --- crates/im-web/assets/main.css | 64 +++++++++++++++++++++----- crates/im-web/src/layout.rs | 52 ++++++++++++++++++++++ crates/im-web/src/pages.rs | 75 +++++++++++++++++-------------- crates/im-web/src/people.rs | 11 ++++- style/main.scss | 84 ++++++++++++++++++++++++++++------- 5 files changed, 225 insertions(+), 61 deletions(-) diff --git a/crates/im-web/assets/main.css b/crates/im-web/assets/main.css index df23d77..d8360dd 100644 --- a/crates/im-web/assets/main.css +++ b/crates/im-web/assets/main.css @@ -399,14 +399,13 @@ body:has(.auth-stage) > .auth-stage::-webkit-scrollbar { font-size: 13px; } -.auth-card .profile-photo-form { +.profile-actions { display: flex; - flex-direction: row; flex-wrap: wrap; gap: 8px; align-items: center; } -.auth-card .profile-photo-form label.admin-action { +.profile-actions label.admin-action { display: inline-flex; align-items: center; box-sizing: border-box; @@ -417,20 +416,65 @@ body:has(.auth-stage) > .auth-stage::-webkit-scrollbar { display: none; } -.profile-photo-save { +#profile-photo-form, +#profile-photo-remove { display: none; } -.profile-photo-form:has(.profile-file-hidden:valid) .profile-photo-save { - display: inline-flex; +.profile-avatar-upload, +.avatar-view { + position: relative; + flex: none; + cursor: pointer; } -#profile-photo-remove { - display: none; +.avatar-view { + appearance: none; + background: none; + border: none; + padding: 0; } -.profile-avatar-upload { - cursor: pointer; +.profile-avatar-upload::after { + content: "+"; + position: absolute; + inset: 0; + display: flex; + align-items: center; + justify-content: center; + background: rgba(0, 0, 0, 0.4); + border-radius: var(--radius); + color: #fff; + font-size: 24px; + font-weight: 300; + opacity: 0; + transition: opacity var(--dur-fast) var(--ease); + pointer-events: none; +} +.profile-avatar-upload:hover::after, .profile-avatar-upload:has(.profile-file-hidden:focus-visible)::after { + opacity: 1; +} + +.viewer-scrim { + position: fixed; + inset: 0; + z-index: 100; + display: flex; + align-items: center; + justify-content: center; + background: rgba(0, 0, 0, 0.65); + cursor: zoom-out; +} + +.viewer { + outline: none; + cursor: default; +} + +.viewer-media { + max-width: min(90vw, 960px); + max-height: 85vh; + border-radius: var(--radius); } .profile-stats { diff --git a/crates/im-web/src/layout.rs b/crates/im-web/src/layout.rs index dfb916b..731203e 100644 --- a/crates/im-web/src/layout.rs +++ b/crates/im-web/src/layout.rs @@ -49,6 +49,58 @@ pub async fn avatar(cx: &Cx, user: &im_core::model::User) -> Result { } } +/// The one script im serves, and the only behavior it carries: the avatar +/// overlay and the picker's autosubmit. A click on a photo `.avatar-view` +/// opens a `.viewer-scrim` around the same `/photo/{id}?v=` URL the avatar +/// reads — the overlay has no server state behind it, so it is client-built +/// and client-closed (scrim click or Escape). A `data-autosubmit` input +/// posts its form on change: choosing a file IS the upload, no Save button. +/// Both are delegated document listeners, so the hard-post re-render never +/// needs rewiring. Emitted by the landing and the person page — every +/// surface that draws a clickable face. +pub async fn avatar_script(cx: &Cx) -> Result { + use topcoat::view::Unescaped; + const JS: &str = "\ + (function () { \ + if (window.__imAvatar) { return; } \ + window.__imAvatar = true; \ + document.addEventListener('click', function (e) { \ + var view = e.target.closest ? e.target.closest('.avatar-view') : null; \ + if (view) { \ + var img = view.querySelector('img.profile-avatar'); \ + if (!img || document.querySelector('.viewer-scrim')) { return; } \ + var scrim = document.createElement('div'); \ + scrim.className = 'viewer-scrim'; \ + var media = document.createElement('img'); \ + media.className = 'viewer-media'; \ + media.src = img.src; \ + media.alt = img.alt; \ + var box = document.createElement('div'); \ + box.className = 'viewer'; \ + box.tabIndex = -1; \ + box.appendChild(media); \ + scrim.appendChild(box); \ + document.body.appendChild(scrim); \ + box.focus(); \ + return; \ + } \ + if (e.target.classList && e.target.classList.contains('viewer-scrim')) { \ + e.target.remove(); \ + } \ + }); \ + document.addEventListener('keydown', function (e) { \ + if (e.key !== 'Escape') { return; } \ + var scrim = document.querySelector('.viewer-scrim'); \ + if (scrim) { scrim.remove(); } \ + }); \ + document.addEventListener('change', function (e) { \ + var input = e.target.closest ? e.target.closest('[data-autosubmit]') : null; \ + if (input && input.form) { input.form.submit(); } \ + }); \ + })();"; + view! { cx => } +} + /// A full document around an already-rendered stage — the same way /// izlek-web's `#[layout]` receives its slot. pub async fn shell(cx: &Cx, title: &str, stage: Result) -> Result { diff --git a/crates/im-web/src/pages.rs b/crates/im-web/src/pages.rs index e0e5e0c..5108672 100644 --- a/crates/im-web/src/pages.rs +++ b/crates/im-web/src/pages.rs @@ -428,12 +428,25 @@ async fn signed_in(cx: &Cx, user: &im_core::model::User) -> Result {
if user.has_photo { - (avatar(cx, user).await?) + // iz's identity row: with a photo, the face opens + // the viewer; Change owns the picker. + } else { - // iz's no-photo idiom: the face itself is the - // upload affordance — the label opens the picker. -
if let Some(code) = ok { @@ -504,6 +502,16 @@ async fn signed_in(cx: &Cx, user: &im_core::model::User) -> Result { "Public profile" + // Both forms carry no visible chrome of their own: the + // picker inputs live on the face and the Change action, + // the remove button in the actions row — all reaching + // here by `form=`. +
if user.has_photo {
Result { + (crate::layout::avatar_script(cx).await?) }; shell(cx, "im", stage).await } diff --git a/crates/im-web/src/people.rs b/crates/im-web/src/people.rs index 51c4e1c..211031c 100644 --- a/crates/im-web/src/people.rs +++ b/crates/im-web/src/people.rs @@ -40,7 +40,15 @@ async fn people_page(cx: &Cx) -> Result { (wordmark(cx).await?)
- (avatar(cx, &person).await?) + if person.has_photo { + // The face opens the viewer here too — same as + // the landing, same as iz's person page. + + } else { + (avatar(cx, &person).await?) + }
(person.name.clone())
@@ -88,6 +96,7 @@ async fn people_page(cx: &Cx) -> Result {
+ (crate::layout::avatar_script(cx).await?) }; shell(cx, &format!("{} · im", person.name), stage).await } diff --git a/style/main.scss b/style/main.scss index db8f6ff..688370f 100644 --- a/style/main.scss +++ b/style/main.scss @@ -441,12 +441,10 @@ body:has(.auth-stage) { font-size: 13px; } -// The photo actions ride the profile head, iz's identity-row idiom: quiet -// row-buttons, the file input itself never seen. The selector outranks -// `.auth-card form`, which would otherwise stack this form vertically. -.auth-card .profile-photo-form { +// The Change/Remove actions ride the profile head, iz's identity-row idiom: +// quiet row-buttons, the file input itself never seen. +.profile-actions { display: flex; - flex-direction: row; flex-wrap: wrap; gap: 8px; align-items: center; @@ -466,26 +464,78 @@ body:has(.auth-stage) { display: none; } -// im serves no script, so iz's autosubmit becomes a Save that appears once -// the input holds a file — `:valid` on a required file input, CSS-only. -.profile-photo-save { +// The forms the actions reach by `form=` carry no visible chrome. +#profile-photo-form, +#profile-photo-remove { display: none; } -.profile-photo-form:has(.profile-file-hidden:valid) .profile-photo-save { - display: inline-flex; +// The two faces of the profile picture box: the picker label and, once a +// photo exists, the viewer trigger — the box rules are shared. +.profile-avatar-upload, +.avatar-view { + position: relative; + flex: none; + cursor: pointer; } -// The remove form carries no visible chrome of its own — its button lives in -// the actions row and reaches it by `form=`. -#profile-photo-remove { - display: none; +// The trigger is the label's box with a button's chrome stripped. +.avatar-view { + appearance: none; + background: none; + border: none; + padding: 0; } -// The no-photo face is the upload affordance: the whole tile opens the -// picker. +// The upload affordance, iz's veil: a plus over the picture, on hover or +// keyboard focus only. .profile-avatar-upload { - cursor: pointer; + &::after { + content: "+"; + position: absolute; + inset: 0; + display: flex; + align-items: center; + justify-content: center; + background: rgb(0 0 0 / 0.4); + border-radius: var(--radius); + color: #fff; + font-size: 24px; + font-weight: 300; + opacity: 0; + transition: opacity var(--dur-fast) var(--ease); + pointer-events: none; + } + + &:hover::after, + &:has(.profile-file-hidden:focus-visible)::after { + opacity: 1; + } +} + +// The photo viewer: a client-built overlay (avatar_script) around the same +// /photo URL the avatar reads — a click on the dimmed ground or Escape +// closes it. +.viewer-scrim { + position: fixed; + inset: 0; + z-index: 100; + display: flex; + align-items: center; + justify-content: center; + background: rgb(0 0 0 / 0.65); + cursor: zoom-out; +} + +.viewer { + outline: none; + cursor: default; +} + +.viewer-media { + max-width: min(90vw, 960px); + max-height: 85vh; + border-radius: var(--radius); } .profile-stats {