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 {