//! The document shell every page renders inside, ported from
//! `iz-web/src/app.rs`'s `shell`/`App`/`NotFound`.
use topcoat::{
Result,
asset::{Asset, asset},
context::Cx,
router::{
StatusCode,
error::{NotFoundError, not_found},
layout, page,
},
view::{BoxView, Unescaped, View, ViewExt, error_boundary, view},
};
use crate::health::{probe_family, switcher_marks};
use crate::i18n::{Key, Lang, t};
use crate::server::{FAMILY_KEY, current_user, store};
/// The iz monogram again, as the tab icon: the same drawing as `wordmark`,
/// inlined because it must carry its own colours — a data URI has no page to
/// inherit `currentColor` or the accent token from, so the two themes are
/// spelled out in a media query inside the SVG.
const FAVICON: &str = "data:image/svg+xml,\
";
/// The iz monogram — a dotted `i` beside a stroked `z`, the trace the product
/// is named for. It takes `currentColor` for its strokes and the accent for
/// its tittle, so one drawing serves both skins and both themes.
///
/// The monogram and the wordmark are alternates, never a pair: `iz` spells the
/// first two letters of `iz`, so standing them side by side reads as a
/// stutter no amount of space or framing repairs. The mark carries the chrome,
/// where the name is already known and the room is 44px; the word carries the
/// front door, where a stranger arrives and nothing else has said it yet.
pub(crate) async fn mark<'a>(cx: &'a Cx) -> Result {
Ok(view! {
cx =>
}
.boxed())
}
/// The wordmark, the monogram's other half: the name alone, in the one face
/// both skins agree on. The sign-in and setup pages wear it — see `mark`.
pub(crate) async fn wordmark<'a>(cx: &'a Cx) -> Result {
Ok(view! {
cx =>
"iz"
}
.boxed())
}
/// A person as a circle (or, on the Instrument skin, a square): the initials,
/// toned by the id so every account has its own colour, with the im photo
/// over it when im has one. The URL carries the row's `photo_version` as
/// `?v=`, so a changed face is a changed URL: a browser may cache the old
/// answer for a year and still see the new one the day the row moves — the
/// live refresh morphs the attribute and the img follows. The `` always
/// renders and hides itself on error (see `avatar_script`), leaving the
/// initials beneath as the fallback. Shared by the board, the modal and
/// every topbar user menu.
pub(crate) async fn avatar<'a>(
cx: &'a Cx,
id: &'a str,
display_name: &'a str,
photo_version: u64,
extra: &'a str,
) -> Result {
let tone = id
.bytes()
.fold(0u32, |acc, b| acc.wrapping_mul(31).wrapping_add(b as u32))
% 5;
let class = format!("avatar avatar-tone-{tone} {extra}");
let initials = initials_of(display_name);
let src = format!("/avatar/{id}?v={photo_version}");
Ok(view! {
cx =>
(initials)
}.boxed())
}
/// The first letters of the first two words, uppercased — "Ada Lovelace"
/// wears "AL", a bare address wears its first letter.
fn initials_of(name: &str) -> String {
let mut out = String::new();
for word in name.split_whitespace().take(2) {
if let Some(first) = word.chars().next() {
out.extend(first.to_uppercase());
}
}
if out.is_empty() {
out.push('?');
}
out
}
/// The photo half's client half: a missing photo must fall back to the
/// initials beneath it, and a bare `` to a 404 shows the broken-image
/// box instead. One document-level capture `error` listener hides every
/// `img.avatar-photo` that fails, plus a sweep for the ones already failed
/// before it ran; hiding is registered through `__izOwn` so the live morph
/// — which owns no names, only what the client declares — does not strip it
/// back off on the next refresh.
pub(crate) async fn avatar_script<'a>(cx: &'a Cx) -> Result {
use topcoat::view::{Unescaped, ViewExt};
const JS: &str = "\
(function () { \
if (window.__izAvatar) { return; } \
window.__izAvatar = true; \
function hide(img) { \
if (window.__izOwn) { window.__izOwn(img, [], ['style']); } \
img.style.display = 'none'; \
} \
document.addEventListener('error', function (e) { \
var img = e.target && e.target.closest ? e.target.closest('img.avatar-photo') : null; \
if (img) { hide(img); } \
}, true); \
document.querySelectorAll('img.avatar-photo').forEach(function (img) { \
if (img.complete && img.naturalWidth === 0) { hide(img); } \
}); \
})();";
Ok(view! { cx => }.boxed())
}
/// The topbar's signed-in identity: the display name, opening on hover or
/// focus onto details (name, address, role) and sign-out. Shared by every
/// signed-in page's topbar — which is why `avatar_script` rides along here:
/// every page with avatars has this menu, and the script's guard makes the
/// one emission enough no matter how many avatars the page carries.
pub async fn user_menu<'a>(
cx: &'a Cx,
me: &'a crate::detail::Me,
lang: Lang,
) -> Result {
let role_key = match me.role {
iz_core::Role::Admin => Key::RoleAdminOption,
iz_core::Role::Member => Key::RoleMemberOption,
iz_core::Role::Viewer => Key::RoleViewerOption,
};
Ok(view! {
cx =>