import { useEffect, useRef } from "react"; import { Link, Outlet, useLocation } from "react-router"; import { SCREEN_LABELS, firstScreen, isScreen, orderScreens, type Screen } from "../auth/roles"; import { useAuth } from "../auth/useAuth"; import { LockScreen } from "./LockScreen"; import { RoleSwitcher } from "./RoleSwitcher"; import { TopBar } from "./TopBar"; function chipClass(s: Screen): string { if (s === "admin") return "rchip admin"; if (s === "supervisor") return "rchip supervisor"; return "rchip"; } /** Page frame: the top bar, then the routed page inside main.wrap, and the lock screen over both. */ export function Layout() { const auth = useAuth(); const { pathname } = useLocation(); const mainRef = useRef(null); const locked = auth.status === "locked"; const me = auth.status === "ready" || locked ? auth.me : null; const screens = me ? orderScreens(me.screens) : []; const seg = pathname.split("/")[1]; const active = isScreen(seg) && screens.includes(seg) ? seg : null; const shown = active ?? firstScreen(screens); // Keep the page mounted behind the lock, but out of reach of the keyboard and screen readers. useEffect(() => { mainRef.current?.toggleAttribute("inert", locked); }, [locked]); return ( <> : null}> {me ? ( <> {me.user.display_name} {shown ? {SCREEN_LABELS[shown]} : null} Account ) : ( Rebuild preview )}
{locked ? : null} ); }