diff --git a/crates/im-web/assets/main.css b/crates/im-web/assets/main.css index 8de56eb..25bc9db 100644 --- a/crates/im-web/assets/main.css +++ b/crates/im-web/assets/main.css @@ -399,13 +399,13 @@ body:has(.auth-stage) > .auth-stage::-webkit-scrollbar { font-size: 13px; } -.profile-actions { +.viewer-actions { display: flex; - flex-wrap: wrap; + justify-content: center; gap: 8px; - align-items: center; + margin-top: 12px; } -.profile-actions label.admin-action { +.viewer-actions label.admin-action { display: inline-flex; align-items: center; box-sizing: border-box; @@ -469,6 +469,9 @@ body:has(.auth-stage) > .auth-stage::-webkit-scrollbar { .viewer { outline: none; cursor: default; + display: flex; + flex-direction: column; + align-items: center; } .viewer-media { @@ -528,45 +531,77 @@ body:has(.auth-stage) > .auth-stage::-webkit-scrollbar { flex-direction: column; } -.session-row { - display: flex; - gap: 12px; - align-items: flex-start; - padding: 12px 0; +.session-item { border-top: 1px solid var(--border-soft); } -.session-row:first-child { +.session-item:first-child { border-top: 0; - padding-top: 0; -} -.session-row:last-child { - padding-bottom: 0; -} -.session-row form { - flex: none; } -.session-main { - flex: 1; +.session-head { display: flex; - flex-direction: column; - gap: 2px; - min-width: 0; + gap: 12px; + align-items: baseline; + padding: 12px 0; + cursor: pointer; + list-style: none; +} +.session-head::-webkit-details-marker { + display: none; } .session-device { font-size: 13px; - overflow-wrap: anywhere; + color: var(--ink); } .session-device .chip { margin-left: 8px; } -.session-meta { +.session-ip { + margin-left: auto; font-size: 12px; color: var(--muted); } +.session-item[open] .session-head { + position: relative; + z-index: 121; +} +.session-item[open] .session-head::after { + content: ""; + position: fixed; + inset: 0; + z-index: -1; + background: rgba(0, 0, 0, 0.65); +} + +.session-detail { + position: fixed; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + z-index: 122; + width: min(90vw, 420px); + max-height: 85vh; + overflow: auto; + background: var(--surface); + border: 1px solid var(--border); + border-radius: var(--radius-lg); + padding: 20px; +} +.session-detail .profile-fields { + margin: 0; +} +.session-detail form { + margin-top: 12px; + text-align: right; +} + +.session-agent { + overflow-wrap: anywhere; +} + @media (max-width: 720px) { .auth-stage { padding: 0 16px 24px; diff --git a/crates/im-web/src/admin.rs b/crates/im-web/src/admin.rs index cf04b89..6ed9951 100644 --- a/crates/im-web/src/admin.rs +++ b/crates/im-web/src/admin.rs @@ -248,7 +248,7 @@ fn sessions_row(user: &User, sessions: &[im_core::sessions::SessionInfo]) -> Str .unwrap_or_else(|_| seen_at.date().to_string()); rows.push_str(&format!( concat!( - r#"{}"#, + r#"{}"#, r#"{}"#, r#"{}"#, r#"{}"#, @@ -259,12 +259,15 @@ fn sessions_row(user: &User, sessions: &[im_core::sessions::SessionInfo]) -> Str r#""#, r#""# ), + // The cell reads as a device; the raw agent rides the title + // for the admin who needs the whole string. session .agent .as_deref() .filter(|agent| !agent.is_empty()) .map(escape) - .unwrap_or_else(|| "Unknown device".to_string()), + .unwrap_or_default(), + escape(&crate::pages::device_label(session.agent.as_deref())), session .ip .as_deref() diff --git a/crates/im-web/src/layout.rs b/crates/im-web/src/layout.rs index d95e4be..b18c0be 100644 --- a/crates/im-web/src/layout.rs +++ b/crates/im-web/src/layout.rs @@ -53,11 +53,13 @@ pub async fn avatar(cx: &Cx, user: &im_core::model::User) -> Result { /// 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. +/// and client-closed (scrim click or Escape). A face marked `data-own` gets +/// the photo's Change/Remove inside the viewer, so the page itself carries +/// no buttons for a picture. 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 = "\ @@ -79,6 +81,22 @@ pub async fn avatar_script(cx: &Cx) -> Result { box.className = 'viewer'; \ box.tabIndex = -1; \ box.appendChild(media); \ + if (view.hasAttribute('data-own')) { \ + var actions = document.createElement('div'); \ + actions.className = 'viewer-actions'; \ + var change = document.createElement('label'); \ + change.className = 'admin-action'; \ + change.setAttribute('for', 'profile-photo-input'); \ + change.textContent = 'Change'; \ + var remove = document.createElement('button'); \ + remove.type = 'submit'; \ + remove.className = 'admin-action admin-danger'; \ + remove.setAttribute('form', 'profile-photo-remove'); \ + remove.textContent = 'Remove'; \ + actions.appendChild(change); \ + actions.appendChild(remove); \ + box.appendChild(actions); \ + } \ scrim.appendChild(box); \ document.body.appendChild(scrim); \ box.focus(); \ @@ -92,6 +110,8 @@ pub async fn avatar_script(cx: &Cx) -> Result { if (e.key !== 'Escape') { return; } \ var scrim = document.querySelector('.viewer-scrim'); \ if (scrim) { scrim.remove(); } \ + var openSession = document.querySelector('.session-item[open]'); \ + if (openSession) { openSession.removeAttribute('open'); } \ }); \ document.addEventListener('change', function (e) { \ var input = e.target.closest ? e.target.closest('[data-autosubmit]') : null; \ @@ -104,6 +124,10 @@ pub async fn avatar_script(cx: &Cx) -> Result { var data = new FormData(form); \ form.__imUploading = true; \ input.disabled = true; \ + /* The picker may have fired from the viewer's Change — the \ + overlay steps aside so the progress row is the thing seen. */ \ + var openScrim = document.querySelector('.viewer-scrim'); \ + if (openScrim) { openScrim.remove(); } \ var row = document.createElement('div'); \ row.className = 'profile-upload-row'; \ var bar = document.createElement('div'); \ diff --git a/crates/im-web/src/pages.rs b/crates/im-web/src/pages.rs index 643f921..a1b824a 100644 --- a/crates/im-web/src/pages.rs +++ b/crates/im-web/src/pages.rs @@ -422,17 +422,43 @@ fn escape(raw: &str) -> String { .replace('"', """) } -/// The device line of a session row: the agent shortened to fit the row, or -/// the honest fallback when the session predates agent capture. -fn device_name(agent: Option<&str>) -> String { - const MAX: usize = 80; - match agent { - None | Some("") => "Unknown device".to_string(), - Some(agent) if agent.chars().count() > MAX => { - format!("{}…", agent.chars().take(MAX).collect::()) - } - Some(agent) => agent.to_string(), - } +/// What the agent string means to a person — "Chrome on Linux", not the raw +/// header. The full string stays one click away in the session's detail. +/// Substring matching in precedence order (Edge before Chrome before Safari: +/// each carries the later one's token too); shared with the admin panel. +pub(crate) fn device_label(agent: Option<&str>) -> String { + let Some(agent) = agent.filter(|agent| !agent.is_empty()) else { + return "Unknown device".to_string(); + }; + let browser = if agent.contains("Edg/") { + "Edge" + } else if agent.contains("Firefox/") { + "Firefox" + } else if agent.contains("Chrome/") { + "Chrome" + } else if agent.contains("Safari/") { + "Safari" + } else { + "Browser" + }; + let system = if agent.contains("iPhone") { + "iPhone" + } else if agent.contains("iPad") { + "iPad" + } else if agent.contains("Android") { + "Android" + } else if agent.contains("Windows") { + "Windows" + } else if agent.contains("Mac OS X") { + "macOS" + } else if agent.contains("CrOS") { + "ChromeOS" + } else if agent.contains("Linux") { + "Linux" + } else { + return browser.to_string(); + }; + format!("{browser} on {system}") } /// `2026-09-04 10:22`: the last-seen stamp. An unrenderable stamp falls back @@ -444,9 +470,13 @@ fn stamp_min(when: time::OffsetDateTime) -> String { .unwrap_or_else(|_| when.date().to_string()) } -/// The sessions card's rows: device, address, stamps, and the per-session -/// revoke. The current row wears the chip and its button reads as the way -/// out of this browser; every other button names what it does instead. +/// The sessions card: one header row per live session — what a person +/// recognizes (device, address, the current one chipped) — with everything +/// else a click behind it. The item is a `
`, so the open state and +/// its modal styling (style/main.scss) work with no script at all; the full +/// agent string, the stamps and the revoke live in the detail. The current +/// session's button reads as the way out of this browser; every other names +/// what it does. fn sessions_html(sessions: &[im_core::sessions::SessionInfo], current: Option<&str>) -> String { let mut rows = String::new(); for session in sessions { @@ -457,26 +487,47 @@ fn sessions_html(sessions: &[im_core::sessions::SessionInfo], current: Option<&s } else { "" }; + let ip = session + .ip + .as_deref() + .map(escape) + .unwrap_or_else(|| "—".to_string()); rows.push_str(&format!( concat!( - r#"
"#, - r#"
{}{}
"#, - r#"
{}
"#, - r#"
Signed in {} · Last seen {}
"#, - r#"
"#, + r#"
"#, + r#"{}{}"#, + r#"{}"#, + r#"
"#, + r#"
"#, + r#"
Device
"#, + r#"
{}
"#, + r#"
Address
"#, + r#"
{}
"#, + r#"
Signed in
"#, + r#"
{}
"#, + r#"
Last seen
"#, + r#"
{}
"#, + r#"
Expires
"#, + r#"
{}
"#, + r#"
"#, r#"
"#, r#""#, - r#"
"# + r#""#, + r#"
"# ), - escape(&device_name(session.agent.as_deref())), + escape(&device_label(session.agent.as_deref())), chip, + ip, session - .ip + .agent .as_deref() + .filter(|agent| !agent.is_empty()) .map(escape) - .unwrap_or_else(|| "—".to_string()), + .unwrap_or_else(|| "Unknown device".to_string()), + ip, session.created_at.date(), stamp_min(seen), + session.expires_at.date(), escape(&session.token_hash), if mine { "Sign out" } else { "Revoke" }, )); @@ -496,8 +547,7 @@ async fn signed_in(cx: &Cx, user: &im_core::model::User) -> Result { let stats = im_core::stats::profile_stats(&server::app(cx).store, &user.id).await?; let joined = user.created_at.date().to_string(); let sessions = im_core::sessions::list_sessions(&server::app(cx).store, &user.id).await?; - let current = - server::presented_session(cx).map(|token| im_core::accounts::hash_token(&token)); + let current = server::presented_session(cx).map(|token| im_core::accounts::hash_token(&token)); let sessions_html = sessions_html(&sessions, current.as_deref()); let stage = view! { cx => @@ -507,11 +557,28 @@ async fn signed_in(cx: &Cx, user: &im_core::model::User) -> Result {
if user.has_photo { - // iz's identity row: with a photo, the face opens - // the viewer; Change owns the picker. - + } else { // Without one, the face itself is the picker: the // label wraps the hidden input, which autosubmits @@ -540,28 +607,6 @@ async fn signed_in(cx: &Cx, user: &im_core::model::User) -> Result { "Admin" }
- if user.has_photo { -
- - -
- }
if let Some(code) = ok { @@ -582,9 +627,8 @@ 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=`. + // picker input hides beside the face, the remove button + // lives in the viewer — all reaching here by `form=`.
, and the open detail +// floats as a card over a dimmed ground. The backdrop is the summary's own +// pseudo-element, so a click anywhere off the card toggles it shut — no +// script at all (avatar_script adds Escape on top). .session-list { display: flex; flex-direction: column; } -.session-row { - display: flex; - gap: 12px; - align-items: flex-start; - padding: 12px 0; +.session-item { border-top: 1px solid var(--border-soft); - &:first-child { - border-top: 0; - padding-top: 0; - } - - &:last-child { padding-bottom: 0; } - - form { flex: none; } + &:first-child { border-top: 0; } } -.session-main { - flex: 1; +.session-head { display: flex; - flex-direction: column; - gap: 2px; - min-width: 0; + gap: 12px; + align-items: baseline; + padding: 12px 0; + cursor: pointer; + list-style: none; + + &::-webkit-details-marker { display: none; } } .session-device { font-size: 13px; - overflow-wrap: anywhere; + color: var(--ink); .chip { margin-left: 8px; } } -.session-meta { +.session-ip { + margin-left: auto; font-size: 12px; color: var(--muted); } +// An open item's header stays above the dim, reading as the card's title. +.session-item[open] .session-head { + position: relative; + z-index: 121; + + &::after { + content: ""; + position: fixed; + inset: 0; + z-index: -1; + background: rgb(0 0 0 / 0.65); + } +} + +.session-detail { + position: fixed; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + z-index: 122; + width: min(90vw, 420px); + max-height: 85vh; + overflow: auto; + background: var(--surface); + border: 1px solid var(--border); + border-radius: var(--radius-lg); + padding: 20px; + + .profile-fields { margin: 0; } + + form { + margin-top: 12px; + text-align: right; + } +} + +// The full agent string is detail content: whole, wrapped, never stretching +// the card. +.session-agent { overflow-wrap: anywhere; } + @media (max-width: 720px) { .auth-stage { padding: 0 16px 24px; } }