import { Show, createEffect, createMemo, createSignal, onCleanup, onMount, type ParentProps } from "solid-js"; import { Dynamic } from "solid-js/web"; import { Link, useLocation, useNavigate } from "@tanstack/solid-router"; import { LogoMark } from "@/components/brand/logo-mark"; import { AccountProfileDialog } from "@/components/users/account-profile-dialog"; import { CelebiPanel } from "@/components/layout/celebi-panel"; import { CommandPalette } from "@/components/layout/command-palette"; import { MobileQuickActions } from "@/components/layout/mobile-quick-actions"; import { MobileTabBar } from "@/components/layout/mobile-tab-bar"; import { NavBar } from "@/components/layout/nav-bar"; import { NetworkStatusBanner } from "@/components/layout/network-status-banner"; import { NotificationCenter } from "@/components/layout/notification-center"; import { routeLabelKey } from "@/components/layout/nav-items"; import { ShellMessagesButton } from "@/components/layout/shell-messages-button"; import { MobileNavSheet } from "@/components/layout/mobile-nav-sheet"; import { SideNav } from "@/components/layout/side-nav"; import { SidebarAccount } from "@/components/layout/sidebar-account"; import { IconSparkles } from "@/components/ui/icons"; import { TooltipTrigger } from "@/components/ui/tooltip"; import { RailTip } from "@/components/layout/rail-tip"; import { Toaster } from "@/components/ui/toast"; import { useAuth } from "@/stores/auth-context"; import { useModules } from "@/stores/modules-context"; import { useSchool } from "@/stores/school-context"; import { celebiPanelOpen, openCelebiPanel, setCelebiPanelOpen } from "@/stores/celebi-panel"; import { commandPaletteOpen, openCommandPalette, setCommandPaletteOpen } from "@/stores/command-palette"; import { quickActionsSuppressed } from "@/stores/quick-actions"; import { ShellFeedProvider } from "@/stores/shell-feed-context"; import { usePreferences, useT } from "@/stores/preferences-context"; import { cn } from "@/lib/cn"; import { createMediaQuery } from "@/lib/create-media-query"; import { ModuleGate } from "@/components/layout/module-gate"; const SIDEBAR_EXPANDED = "w-[260px]"; // 56px: the icon rail, in the 48–56px band Linear and shadcn's icon mode use. const SIDEBAR_COLLAPSED = "w-14"; export function AppShell(props: ParentProps) { const auth = useAuth(); const prefs = usePreferences(); const t = useT(); const school = useSchool(); const modules = useModules(); const navigate = useNavigate(); const [mobileOpen, setMobileOpen] = createSignal(false); const [profileOpen, setProfileOpen] = createSignal(false); const collapsed = () => prefs.sidebarCollapsed(); const brandLabel = () => (school.name() ? `${t("app.name")} · ${school.name()}` : t("app.name")); const location = useLocation(); const fullScreen = () => location().pathname.startsWith("/exam-room/"); // Below lg the header gives way to the floating action button. Chosen in // JS rather than with CSS so only one of the two notification surfaces is // mounted, and their dismissed state never has two in-memory copies. const phone = createMediaQuery("(max-width: 63.98rem)"); const routeLabel = createMemo(() => { const key = routeLabelKey(location().pathname, auth.user()?.role, location().search as Record); return key ? t(key) : ""; }); // The page's own h1, when it renders one (detail pages, the 404). Watched // rather than declared per route: the shell names the page with an h1 of its // own only where the page has none, so no screen ends up with two. let content: HTMLDivElement | undefined; const [pageHeading, setPageHeading] = createSignal(null); onMount(() => { if (!content || typeof MutationObserver === "undefined") return; const read = () => { const heading = content?.querySelector("h1:not([data-shell-title])"); setPageHeading(heading ? (heading.textContent ?? "").trim() : null); }; read(); const observer = new MutationObserver(read); observer.observe(content, { childList: true, subtree: true, characterData: true }); onCleanup(() => observer.disconnect()); }); // Unlisted routes (an instance, the 404) borrow the page's own heading. const pageTitle = () => routeLabel() || pageHeading() || ""; // One place names the browser tab for every shell route, from the same // label the header shows. createEffect(() => { const label = pageTitle(); document.title = label ? `${label} · ${t("app.name")}` : t("app.name"); }); const shellChrome = () => Boolean(auth.user()) && !fullScreen(); // Room below the last row for the quick-action button resting over the tab // bar, so a pager or a last card's actions can scroll clear of it. // A board fills the content column edge to edge; the floating button sat // on its bottom-right corner, over the canvas's own controls. const boardPage = () => /^\/whiteboards\/[^/]+/.test(location().pathname); const fabHidden = () => quickActionsSuppressed() || boardPage(); const fabClearance = () => shellChrome() && phone() && !fabHidden(); const logout = async () => { await auth.logout(); void navigate({ to: "/login" }); }; return (
{t("common.skipToContent")}
setMobileOpen(false)} onLogout={logout} onOpenCelebi={() => openCelebiPanel()} onOpenProfile={() => setProfileOpen(true)} /> {/* The menu sheet is modal: what it covers leaves the tab order and the accessibility tree while it is up. */}
{/* Account context first, Cloudflare-style: "School / Page". */} {(name) => ( <> )} {/* The page's h1 unless the page renders its own. */}
{/* The skip link's target starts below the header, so it lands on the page rather than on the header's controls. */}
{ content = el; }} class={cn( // Every page fills the content column, as Messages always did: a // fixed 1180px cap left wide screens mostly empty margin. "w-full px-4 py-6 outline-hidden sm:px-6 lg:px-10 lg:py-6", shellChrome() && "pb-[calc(3.5rem+max(env(safe-area-inset-bottom),var(--android-nav-inset,0px)))] lg:pb-6", fabClearance() && "pb-[calc(9rem+max(env(safe-area-inset-bottom),var(--android-nav-inset,0px)))]", )} > {/* No header below lg, so the page title opens the content. */}

{pageTitle()}

{props.children}
{/* MobileTabBar and the quick actions stay inside the provider — they are shell surfaces, so a useShellFeed() badge there must not throw. */}
setMobileOpen(true)} onSearch={openCommandPalette} />
openCelebiPanel()} onOpenProfile={() => setProfileOpen(true)} />
); }