forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

app-shell.tsx197 lines, 9.0 KiBHistoryRawDownload
1import { Show, createEffect, createMemo, createSignal, type ParentProps } from "solid-js";
2import { Link, useLocation, useNavigate } from "@tanstack/solid-router";
3import { LogoMark } from "@/components/brand/logo-mark";
4import { AccountProfileDialog } from "@/components/users/account-profile-dialog";
5import { CelebiPanel } from "@/components/layout/celebi-panel";
6import { CommandPalette } from "@/components/layout/command-palette";
7import { MobileTabBar } from "@/components/layout/mobile-tab-bar";
8import { NavBar } from "@/components/layout/nav-bar";
9import { NetworkStatusBanner } from "@/components/layout/network-status-banner";
10import { NotificationCenter } from "@/components/layout/notification-center";
11import { routeLabelKey } from "@/components/layout/nav-items";
12import { ShellMessagesButton } from "@/components/layout/shell-messages-button";
13import { MobileNavSheet } from "@/components/layout/mobile-nav-sheet";
14import { SideNav } from "@/components/layout/side-nav";
15import { SidebarAccount } from "@/components/layout/sidebar-account";
16import { IconPanelLeft, IconSparkles } from "@/components/ui/icons";
17import { Toaster } from "@/components/ui/toast";
18import { useAuth } from "@/stores/auth-context";
19import { useModules } from "@/stores/modules-context";
20import { celebiPanelOpen, openCelebiPanel, setCelebiPanelOpen } from "@/stores/celebi-panel";
21import { commandPaletteOpen, openCommandPalette, setCommandPaletteOpen } from "@/stores/command-palette";
22import { ShellFeedProvider } from "@/stores/shell-feed-context";
23import { usePreferences, useT } from "@/stores/preferences-context";
24import { cn } from "@/lib/cn";
25import { ModuleGate } from "@/components/layout/module-gate";
26
27const SIDEBAR_EXPANDED = "w-[260px]";
28const SIDEBAR_COLLAPSED = "w-24";
29
30export function AppShell(props: ParentProps) {
31 const auth = useAuth();
32 const prefs = usePreferences();
33 const t = useT();
34 const modules = useModules();
35 const navigate = useNavigate();
36 const [mobileOpen, setMobileOpen] = createSignal(false);
37 const [profileOpen, setProfileOpen] = createSignal(false);
38 const collapsed = () => prefs.sidebarCollapsed();
39 const location = useLocation();
40 const fullScreen = () => location().pathname.startsWith("/exam-room/");
41 const routeLabel = createMemo(() => {
42 const key = routeLabelKey(location().pathname, auth.user()?.role);
43 return key ? t(key) : "";
44 });
45 // One place names the browser tab for every shell route, from the same
46 // label the header shows.
47 createEffect(() => {
48 const label = routeLabel();
49 document.title = label ? `${label} · ${t("app.name")}` : t("app.name");
50 });
51 const logout = async () => {
52 await auth.logout();
53 void navigate({ to: "/login" });
54 };
55
56 return (
57 <div class="min-h-[var(--app-viewport)] bg-background text-foreground">
58 <a
59 href="#main-content"
60 class="sr-only focus:not-sr-only focus:fixed focus:left-3 focus:top-3 focus:z-[90] focus:rounded-md focus:bg-surface-base focus:px-3 focus:py-2 focus:text-sm focus:font-medium focus:shadow-lg focus:ring-2 focus:ring-ring"
61 >
62 {t("common.skipToContent")}
63 </a>
64 <Show when={!auth.user()}>
65 <NavBar />
66 </Show>
67 <ShellFeedProvider>
68 <div class="flex w-full">
69 <Show when={auth.user() && !fullScreen()}>
70 <aside
71 class={cn(
72 "sticky top-[env(safe-area-inset-top)] z-40 hidden h-[var(--app-viewport)] shrink-0 border-r border-border bg-sidebar text-sidebar-foreground transition-[width] duration-200 ease-out lg:flex lg:flex-col",
73 collapsed() ? SIDEBAR_COLLAPSED : SIDEBAR_EXPANDED,
74 )}
75 >
76 <div
77 class={cn(
78 "flex h-[45px] shrink-0 items-center border-b border-border/70",
79 collapsed() ? "justify-center px-2" : "px-3",
80 )}
81 >
82 <Link
83 to="/"
84 class={cn("flex min-w-0 items-center gap-2.5", collapsed() ? "justify-center" : "flex-1")}
85 title={t("app.name")}
86 >
87 <span class="flex h-8 w-8 shrink-0 items-center justify-center text-foreground">
88 <LogoMark size={28} />
89 </span>
90 <Show when={!collapsed()}>
91 <span class="truncate text-base font-semibold tracking-tight text-foreground dark:text-white 2xl:text-lg">{t("app.name")}</span>
92 </Show>
93 </Link>
94 </div>
95
96 <div class="min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-1.5 py-2.5">
97 <SideNav
98 collapsed={collapsed()}
99 onOpenCelebi={() => openCelebiPanel()}
100 onOpenProfile={() => setProfileOpen(true)}
101 />
102 </div>
103
104 <SidebarAccount collapsed={collapsed()} onLogout={logout} />
105
106 {/* Collapse toggle rides the corner where the sidebar's right edge
107 meets the header's bottom border. */}
108 <button
109 type="button"
110 class="absolute right-0 top-[45px] z-10 flex h-7 w-7 -translate-y-1/2 translate-x-1/2 items-center justify-center rounded-md border border-border bg-background text-muted-foreground shadow-xs outline-hidden transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
111 aria-label={collapsed() ? t("nav.expand") : t("nav.collapse")}
112 aria-expanded={!collapsed()}
113 title={collapsed() ? t("nav.expand") : t("nav.collapse")}
114 onClick={() => prefs.toggleSidebar()}
115 >
116 <IconPanelLeft class={cn("h-4 w-4 transition-transform duration-200", collapsed() && "rotate-180")} />
117 </button>
118
119 </aside>
120 </Show>
121
122 <Show when={auth.user()}>
123 <MobileNavSheet
124 open={mobileOpen()}
125 onClose={() => setMobileOpen(false)}
126 onLogout={logout}
127 onOpenCelebi={() => openCelebiPanel()}
128 onOpenProfile={() => setProfileOpen(true)}
129 />
130 </Show>
131
132 <main id="main-content" tabIndex={-1} class="min-w-0 flex-1 outline-hidden">
133 <Show when={auth.user() && !fullScreen()}>
134 <header class="sticky top-[env(safe-area-inset-top)] z-30 flex h-[49px] items-center gap-3 border-b border-border/70 bg-background px-4 pt-1.5 sm:px-6 lg:px-4">
135 <div class="flex min-w-0 shrink-0 items-center gap-2 sm:w-52 lg:w-[260px]">
136 <span class="hidden truncate text-sm font-semibold sm:block" title={routeLabel()}>{routeLabel()}</span>
137 </div>
138
139 <div class="min-w-0 flex-1" />
140
141 <div class="flex shrink-0 items-center justify-end gap-2">
142 <Show when={modules.isEnabled("messages")}>
143 <ShellMessagesButton />
144 </Show>
145 <NotificationCenter />
146 <Show when={modules.isEnabled("chatbot")}>
147 <button
148 type="button"
149 class="topbar-ai-control hidden h-9 shrink-0 items-center justify-center gap-2 rounded-md px-3 text-xs font-semibold outline-hidden focus-visible:ring-2 focus-visible:ring-ring active:scale-[0.98] sm:flex"
150 aria-label={t("ai.askCelebi")}
151 title={t("ai.askCelebi")}
152 onClick={() => openCelebiPanel()}
153 >
154 <IconSparkles class="h-4 w-4" />
155 <span>{t("ai.askCelebi")}</span>
156 </button>
157 </Show>
158 </div>
159 </header>
160 </Show>
161 <Show when={auth.user() && !fullScreen()}>
162 <NetworkStatusBanner />
163 </Show>
164 <div
165 class={cn(
166 // Every page fills the content column, as Messages always did: a
167 // fixed 1180px cap left wide screens mostly empty margin.
168 "w-full px-4 py-6 sm:px-6 lg:px-10 lg:py-6",
169 auth.user() && !fullScreen() && "pb-[calc(3.5rem+max(env(safe-area-inset-bottom),var(--android-nav-inset,0px)))] lg:pb-6",
170 )}
171 >
172 <Show when={auth.user()} fallback={props.children}>
173 <ModuleGate>{props.children}</ModuleGate>
174 </Show>
175 </div>
176 </main>
177 </div>
178 {/* MobileTabBar stays inside the provider — it is a shell surface, so a
179 useShellFeed() badge there must not throw. */}
180 <Show when={auth.user() && !fullScreen()}>
181 <MobileTabBar onMenu={() => setMobileOpen(true)} onSearch={openCommandPalette} />
182 </Show>
183 </ShellFeedProvider>
184 <Show when={auth.user()}>
185 <CelebiPanel open={celebiPanelOpen()} onOpenChange={setCelebiPanelOpen} />
186 <CommandPalette
187 open={commandPaletteOpen()}
188 onOpenChange={setCommandPaletteOpen}
189 onOpenCelebi={() => openCelebiPanel()}
190 onOpenProfile={() => setProfileOpen(true)}
191 />
192 <AccountProfileDialog open={profileOpen()} onOpenChange={setProfileOpen} />
193 </Show>
194 <Toaster />
195 </div>
196 );
197}