forge
Explore
Log in

Don't you dare go Hollow

Avatar is the picker; photos autosubmit; the face opens a viewer

Browse files at this commit

f09955969e9a995e9ad76324eea0d12ac99d00b5Ahmet Kaan GümüşParent: 99c1ffe
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.cssmodified+54 -10
@@ -399,14 +399,13 @@ body:has(.auth-stage) > .auth-stage::-webkit-scrollbar {
399 font-size: 13px;399 font-size: 13px;
400 }400 }
401 401
402-.auth-card .profile-photo-form {402+.profile-actions {
403 display: flex;403 display: flex;
404- flex-direction: row;
405 flex-wrap: wrap;404 flex-wrap: wrap;
406 gap: 8px;405 gap: 8px;
407 align-items: center;406 align-items: center;
408 }407 }
409-.auth-card .profile-photo-form label.admin-action {408+.profile-actions label.admin-action {
410 display: inline-flex;409 display: inline-flex;
411 align-items: center;410 align-items: center;
412 box-sizing: border-box;411 box-sizing: border-box;
@@ -417,20 +416,65 @@ body:has(.auth-stage) > .auth-stage::-webkit-scrollbar {
417 display: none;416 display: none;
418 }417 }
419 418
420-.profile-photo-save {419+#profile-photo-form,
420+#profile-photo-remove {
421 display: none;421 display: none;
422 }422 }
423 423
424-.profile-photo-form:has(.profile-file-hidden:valid) .profile-photo-save {424+.profile-avatar-upload,
425- display: inline-flex;425+.avatar-view {
426+ position: relative;
427+ flex: none;
428+ cursor: pointer;
426 }429 }
427 430
428-#profile-photo-remove {431+.avatar-view {
429- display: none;432+ appearance: none;
433+ background: none;
434+ border: none;
435+ padding: 0;
430 }436 }
431 437
432-.profile-avatar-upload {438+.profile-avatar-upload::after {
433- cursor: pointer;439+ content: "+";
440+ position: absolute;
441+ inset: 0;
442+ display: flex;
443+ align-items: center;
444+ justify-content: center;
445+ background: rgba(0, 0, 0, 0.4);
446+ border-radius: var(--radius);
447+ color: #fff;
448+ font-size: 24px;
449+ font-weight: 300;
450+ opacity: 0;
451+ transition: opacity var(--dur-fast) var(--ease);
452+ pointer-events: none;
453+}
454+.profile-avatar-upload:hover::after, .profile-avatar-upload:has(.profile-file-hidden:focus-visible)::after {
455+ opacity: 1;
456+}
457+
458+.viewer-scrim {
459+ position: fixed;
460+ inset: 0;
461+ z-index: 100;
462+ display: flex;
463+ align-items: center;
464+ justify-content: center;
465+ background: rgba(0, 0, 0, 0.65);
466+ cursor: zoom-out;
467+}
468+
469+.viewer {
470+ outline: none;
471+ cursor: default;
472+}
473+
474+.viewer-media {
475+ max-width: min(90vw, 960px);
476+ max-height: 85vh;
477+ border-radius: var(--radius);
434 }478 }
435 479
436 .profile-stats {480 .profile-stats {
crates/im-web/src/layout.rsmodified+52 -0
@@ -49,6 +49,58 @@ pub async fn avatar(cx: &Cx, user: &im_core::model::User) -> Result {
49 }49 }
50 }50 }
51 51
52+/// The one script im serves, and the only behavior it carries: the avatar
53+/// overlay and the picker's autosubmit. A click on a photo `.avatar-view`
54+/// opens a `.viewer-scrim` around the same `/photo/{id}?v=` URL the avatar
55+/// reads — the overlay has no server state behind it, so it is client-built
56+/// and client-closed (scrim click or Escape). A `data-autosubmit` input
57+/// posts its form on change: choosing a file IS the upload, no Save button.
58+/// Both are delegated document listeners, so the hard-post re-render never
59+/// needs rewiring. Emitted by the landing and the person page — every
60+/// surface that draws a clickable face.
61+pub async fn avatar_script(cx: &Cx) -> Result {
62+ use topcoat::view::Unescaped;
63+ const JS: &str = "\
64+ (function () { \
65+ if (window.__imAvatar) { return; } \
66+ window.__imAvatar = true; \
67+ document.addEventListener('click', function (e) { \
68+ var view = e.target.closest ? e.target.closest('.avatar-view') : null; \
69+ if (view) { \
70+ var img = view.querySelector('img.profile-avatar'); \
71+ if (!img || document.querySelector('.viewer-scrim')) { return; } \
72+ var scrim = document.createElement('div'); \
73+ scrim.className = 'viewer-scrim'; \
74+ var media = document.createElement('img'); \
75+ media.className = 'viewer-media'; \
76+ media.src = img.src; \
77+ media.alt = img.alt; \
78+ var box = document.createElement('div'); \
79+ box.className = 'viewer'; \
80+ box.tabIndex = -1; \
81+ box.appendChild(media); \
82+ scrim.appendChild(box); \
83+ document.body.appendChild(scrim); \
84+ box.focus(); \
85+ return; \
86+ } \
87+ if (e.target.classList && e.target.classList.contains('viewer-scrim')) { \
88+ e.target.remove(); \
89+ } \
90+ }); \
91+ document.addEventListener('keydown', function (e) { \
92+ if (e.key !== 'Escape') { return; } \
93+ var scrim = document.querySelector('.viewer-scrim'); \
94+ if (scrim) { scrim.remove(); } \
95+ }); \
96+ document.addEventListener('change', function (e) { \
97+ var input = e.target.closest ? e.target.closest('[data-autosubmit]') : null; \
98+ if (input && input.form) { input.form.submit(); } \
99+ }); \
100+ })();";
101+ view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }
102+}
103+
52 /// A full document around an already-rendered stage — the same way104 /// A full document around an already-rendered stage — the same way
53 /// izlek-web's `#[layout]` receives its slot.105 /// izlek-web's `#[layout]` receives its slot.
54 pub async fn shell(cx: &Cx, title: &str, stage: Result) -> Result {106 pub async fn shell(cx: &Cx, title: &str, stage: Result) -> Result {
crates/im-web/src/pages.rsmodified+42 -33
@@ -428,12 +428,25 @@ async fn signed_in(cx: &Cx, user: &im_core::model::User) -> Result {
428 <div class="auth-card">428 <div class="auth-card">
429 <div class="profile-head">429 <div class="profile-head">
430 if user.has_photo {430 if user.has_photo {
431- (avatar(cx, user).await?)431+ // iz's identity row: with a photo, the face opens
432+ // the viewer; Change owns the picker.
433+ <button class="avatar-view" type="button" aria-label="View photo">
434+ (avatar(cx, user).await?)
435+ </button>
432 } else {436 } else {
433- // iz's no-photo idiom: the face itself is the437+ // Without one, the face itself is the picker: the
434- // upload affordance — the label opens the picker.438+ // label wraps the hidden input, which autosubmits
435- <label class="profile-avatar-upload" for="profile-photo-input">439+ // on change (avatar_script) — no buttons at all.
440+ <label class="profile-avatar-upload">
436 (avatar(cx, user).await?)441 (avatar(cx, user).await?)
442+ <input
443+ class="profile-file-hidden"
444+ type="file"
445+ name="photo"
446+ accept="image/png,image/jpeg,image/gif,image/webp,image/avif"
447+ form="profile-photo-form"
448+ data-autosubmit=""
449+ >
437 </label>450 </label>
438 }451 }
439 <div class="profile-heading">452 <div class="profile-heading">
@@ -448,34 +461,19 @@ async fn signed_in(cx: &Cx, user: &im_core::model::User) -> Result {
448 <span class="chip chip-accent">"Admin"</span>461 <span class="chip chip-accent">"Admin"</span>
449 }462 }
450 </div>463 </div>
451- <form464+ if user.has_photo {
452- class="profile-photo-form"465+ <div class="profile-actions">
453- method="post"466+ <label class="admin-action">
454- action="/api/profile_photo"
455- enctype="multipart/form-data"
456- >
457- <input
458- id="profile-photo-input"
459- class="profile-file-hidden"
460- type="file"
461- name="photo"
462- accept="image/png,image/jpeg,image/gif,image/webp,image/avif"
463- required=""
464- >
465- <label class="admin-action" for="profile-photo-input">
466- if user.has_photo {
467 "Change"467 "Change"
468- } else {468+ <input
469- "Add photo"469+ class="profile-file-hidden"
470- }470+ type="file"
471- </label>471+ name="photo"
472- // No script on im: where iz auto-submits on472+ accept="image/png,image/jpeg,image/gif,image/webp,image/avif"
473- // change, a quiet Save appears once the input473+ form="profile-photo-form"
474- // holds a file (`:has(:valid)`, CSS-only).474+ data-autosubmit=""
475- <button class="admin-action profile-photo-save" type="submit">475+ >
476- "Save"476+ </label>
477- </button>
478- if user.has_photo {
479 <button477 <button
480 class="admin-action"478 class="admin-action"
481 type="submit"479 type="submit"
@@ -483,8 +481,8 @@ async fn signed_in(cx: &Cx, user: &im_core::model::User) -> Result {
483 >481 >
484 "Remove"482 "Remove"
485 </button>483 </button>
486- }484+ </div>
487- </form>485+ }
488 </div>486 </div>
489 </div>487 </div>
490 if let Some(code) = ok {488 if let Some(code) = ok {
@@ -504,6 +502,16 @@ async fn signed_in(cx: &Cx, user: &im_core::model::User) -> Result {
504 </div>502 </div>
505 </dl>503 </dl>
506 <a class="auth-alt" href=(format!("/people/{}", user.id))>"Public profile"</a>504 <a class="auth-alt" href=(format!("/people/{}", user.id))>"Public profile"</a>
505+ // Both forms carry no visible chrome of their own: the
506+ // picker inputs live on the face and the Change action,
507+ // the remove button in the actions row — all reaching
508+ // here by `form=`.
509+ <form
510+ id="profile-photo-form"
511+ method="post"
512+ action="/api/profile_photo"
513+ enctype="multipart/form-data"
514+ ></form>
507 if user.has_photo {515 if user.has_photo {
508 <form516 <form
509 id="profile-photo-remove"517 id="profile-photo-remove"
@@ -541,6 +549,7 @@ async fn signed_in(cx: &Cx, user: &im_core::model::User) -> Result {
541 <div class="auth-footer">"im · Dizey SSO"</div>549 <div class="auth-footer">"im · Dizey SSO"</div>
542 </div>550 </div>
543 </main>551 </main>
552+ (crate::layout::avatar_script(cx).await?)
544 };553 };
545 shell(cx, "im", stage).await554 shell(cx, "im", stage).await
546 }555 }
crates/im-web/src/people.rsmodified+10 -1
@@ -40,7 +40,15 @@ async fn people_page(cx: &Cx) -> Result {
40 (wordmark(cx).await?)40 (wordmark(cx).await?)
41 <div class="auth-card">41 <div class="auth-card">
42 <div class="profile-head">42 <div class="profile-head">
43- (avatar(cx, &person).await?)43+ if person.has_photo {
44+ // The face opens the viewer here too — same as
45+ // the landing, same as iz's person page.
46+ <button class="avatar-view" type="button" aria-label="View photo">
47+ (avatar(cx, &person).await?)
48+ </button>
49+ } else {
50+ (avatar(cx, &person).await?)
51+ }
44 <div class="profile-heading">52 <div class="profile-heading">
45 <div class="auth-title">(person.name.clone())</div>53 <div class="auth-title">(person.name.clone())</div>
46 <div class="profile-marks">54 <div class="profile-marks">
@@ -88,6 +96,7 @@ async fn people_page(cx: &Cx) -> Result {
88 <div class="auth-footer">"im · Dizey SSO"</div>96 <div class="auth-footer">"im · Dizey SSO"</div>
89 </div>97 </div>
90 </main>98 </main>
99+ (crate::layout::avatar_script(cx).await?)
91 };100 };
92 shell(cx, &format!("{} · im", person.name), stage).await101 shell(cx, &format!("{} · im", person.name), stage).await
93 }102 }
style/main.scssmodified+67 -17
@@ -441,12 +441,10 @@ body:has(.auth-stage) {
441 font-size: 13px;441 font-size: 13px;
442 }442 }
443 443
444-// The photo actions ride the profile head, iz's identity-row idiom: quiet444+// The Change/Remove actions ride the profile head, iz's identity-row idiom:
445-// row-buttons, the file input itself never seen. The selector outranks445+// quiet row-buttons, the file input itself never seen.
446-// `.auth-card form`, which would otherwise stack this form vertically.446+.profile-actions {
447-.auth-card .profile-photo-form {
448 display: flex;447 display: flex;
449- flex-direction: row;
450 flex-wrap: wrap;448 flex-wrap: wrap;
451 gap: 8px;449 gap: 8px;
452 align-items: center;450 align-items: center;
@@ -466,26 +464,78 @@ body:has(.auth-stage) {
466 display: none;464 display: none;
467 }465 }
468 466
469-// im serves no script, so iz's autosubmit becomes a Save that appears once467+// The forms the actions reach by `form=` carry no visible chrome.
470-// the input holds a file — `:valid` on a required file input, CSS-only.468+#profile-photo-form,
471-.profile-photo-save {469+#profile-photo-remove {
472 display: none;470 display: none;
473 }471 }
474 472
475-.profile-photo-form:has(.profile-file-hidden:valid) .profile-photo-save {473+// The two faces of the profile picture box: the picker label and, once a
476- display: inline-flex;474+// photo exists, the viewer trigger — the box rules are shared.
475+.profile-avatar-upload,
476+.avatar-view {
477+ position: relative;
478+ flex: none;
479+ cursor: pointer;
477 }480 }
478 481
479-// The remove form carries no visible chrome of its own — its button lives in482+// The trigger is the label's box with a button's chrome stripped.
480-// the actions row and reaches it by `form=`.483+.avatar-view {
481-#profile-photo-remove {484+ appearance: none;
482- display: none;485+ background: none;
486+ border: none;
487+ padding: 0;
483 }488 }
484 489
485-// The no-photo face is the upload affordance: the whole tile opens the490+// The upload affordance, iz's veil: a plus over the picture, on hover or
486-// picker.491+// keyboard focus only.
487 .profile-avatar-upload {492 .profile-avatar-upload {
488- cursor: pointer;493+ &::after {
494+ content: "+";
495+ position: absolute;
496+ inset: 0;
497+ display: flex;
498+ align-items: center;
499+ justify-content: center;
500+ background: rgb(0 0 0 / 0.4);
501+ border-radius: var(--radius);
502+ color: #fff;
503+ font-size: 24px;
504+ font-weight: 300;
505+ opacity: 0;
506+ transition: opacity var(--dur-fast) var(--ease);
507+ pointer-events: none;
508+ }
509+
510+ &:hover::after,
511+ &:has(.profile-file-hidden:focus-visible)::after {
512+ opacity: 1;
513+ }
514+}
515+
516+// The photo viewer: a client-built overlay (avatar_script) around the same
517+// /photo URL the avatar reads — a click on the dimmed ground or Escape
518+// closes it.
519+.viewer-scrim {
520+ position: fixed;
521+ inset: 0;
522+ z-index: 100;
523+ display: flex;
524+ align-items: center;
525+ justify-content: center;
526+ background: rgb(0 0 0 / 0.65);
527+ cursor: zoom-out;
528+}
529+
530+.viewer {
531+ outline: none;
532+ cursor: default;
533+}
534+
535+.viewer-media {
536+ max-width: min(90vw, 960px);
537+ max-height: 85vh;
538+ border-radius: var(--radius);
489 }539 }
490 540
491 .profile-stats {541 .profile-stats {