forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBc35a83aBurak Boduroğlu4 months ago440 commits

app-shell.tsx211 lines, 10.1 KiBHistoryRawDownload
1import { Show, createMemo, createSignal, type ParentProps } from "solid-js";
2import { Link, useLocation, useNavigate } from "@tanstack/solid-router";
3import { AccountProfileDialog } from "@/components/users/account-profile-dialog";
4import { CelebiPanel } from "@/components/layout/celebi-panel";
5import { CommandPalette } from "@/components/layout/command-palette";
6import { MobileTabBar } from "@/components/layout/mobile-tab-bar";
7import { NavBar } from "@/components/layout/nav-bar";
8import { NotificationCenter } from "@/components/layout/notification-center";
9import { routeNavItem } from "@/components/layout/nav-items";
10import { ShellMessagesButton } from "@/components/layout/shell-messages-button";
11import { SideNav } from "@/components/layout/side-nav";
12import { SidebarAccount } from "@/components/layout/sidebar-account";
13import { Button } from "@/components/ui/button";
14import { IconChevronLeft, IconPanelLeft, IconSearch, IconSparkles, IconX } from "@/components/ui/icons";
15import { Toaster } from "@/components/ui/toast";
16import { useAuth } from "@/stores/auth-context";
17import { ShellFeedProvider } from "@/stores/shell-feed-context";
18import { usePreferences, useT } from "@/stores/preferences-context";
19import { cn } from "@/lib/cn";
20
21const SIDEBAR_EXPANDED = "w-60";
22const SIDEBAR_COLLAPSED = "w-24";
23
24export function AppShell(props: ParentProps) {
25 const auth = useAuth();
26 const prefs = usePreferences();
27 const t = useT();
28 const navigate = useNavigate();
29 const [mobileOpen, setMobileOpen] = createSignal(false);
30 const [celebiOpen, setCelebiOpen] = createSignal(false);
31 const [commandOpen, setCommandOpen] = createSignal(false);
32 const [profileOpen, setProfileOpen] = createSignal(false);
33 const collapsed = () => prefs.sidebarCollapsed();
34 const location = useLocation();
35 const wide = () => location().pathname.startsWith("/exam-room/") || location().searchStr.includes("answerUser=") || location().pathname === "/messages";
36 const fullScreen = () => location().pathname.startsWith("/exam-room/");
37 const routeLabel = createMemo(() => {
38 const item = routeNavItem(location().pathname, auth.user()?.role);
39 return item ? t(item.labelKey) : location().pathname;
40 });
41 const logout = async () => {
42 await auth.logout();
43 void navigate({ to: "/login" });
44 };
45
46 return (
47 <div class="min-h-screen bg-background text-foreground">
48 <Show when={!auth.user()}>
49 <NavBar />
50 </Show>
51 <ShellFeedProvider>
52 <div class="flex w-full">
53 <Show when={auth.user() && !fullScreen()}>
54 <aside
55 class={cn(
56 "sticky top-0 z-30 hidden h-screen shrink-0 border-r border-border bg-sidebar text-sidebar-foreground transition-[width] duration-200 ease-out lg:flex lg:flex-col",
57 collapsed() ? SIDEBAR_COLLAPSED : SIDEBAR_EXPANDED,
58 )}
59 >
60 <div
61 class={cn(
62 "flex shrink-0 items-center gap-2 border-b border-border/70",
63 collapsed() ? "h-auto flex-col justify-center gap-1.5 px-2 py-2" : "h-16 px-3",
64 )}
65 >
66 <Link
67 to="/"
68 class={cn("flex min-w-0 items-center gap-2.5", collapsed() ? "justify-center" : "flex-1")}
69 title={t("app.name")}
70 >
71 <span class="flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-primary text-xs font-bold text-primary-foreground">
72 H
73 </span>
74 <Show when={!collapsed()}>
75 <span class="truncate text-base font-semibold tracking-tight text-foreground dark:text-white 2xl:text-lg">{t("app.name")}</span>
76 </Show>
77 </Link>
78 <Button
79 type="button"
80 variant="ghost"
81 size="sm"
82 class="h-8 w-8 shrink-0 justify-center rounded-md px-0 text-muted-foreground hover:bg-secondary hover:text-foreground dark:text-white/70 dark:hover:bg-white/8 dark:hover:text-white"
83 aria-label={collapsed() ? t("nav.expand") : t("nav.collapse")}
84 title={collapsed() ? t("nav.expand") : t("nav.collapse")}
85 onClick={() => prefs.toggleSidebar()}
86 >
87 <IconPanelLeft class={cn("h-4 w-4 shrink-0 transition-transform duration-200", collapsed() && "scale-x-[-1]")} />
88 </Button>
89 </div>
90
91 <div class="min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-1.5 py-2.5">
92 <SideNav collapsed={collapsed()} />
93 </div>
94
95 <SidebarAccount collapsed={collapsed()} onLogout={logout} />
96 </aside>
97 </Show>
98
99 <Show when={mobileOpen() && auth.user()}>
100 <div class="fixed inset-0 z-50 lg:hidden">
101 <button
102 type="button"
103 class="absolute inset-0 bg-black/40 transition-opacity"
104 aria-label={t("nav.close")}
105 onClick={() => setMobileOpen(false)}
106 />
107 <aside class="absolute inset-y-0 left-0 flex w-60 max-w-[85vw] flex-col border-r border-border bg-sidebar text-sidebar-foreground shadow-2xl shadow-black/20">
108 <div class="flex h-14 shrink-0 items-center justify-between gap-2 border-b border-border px-3">
109 <Link to="/" class="flex min-w-0 items-center gap-2.5" onClick={() => setMobileOpen(false)}>
110 <span class="flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-primary text-xs font-bold text-primary-foreground">H</span>
111 <span class="truncate text-base font-semibold text-foreground dark:text-white">{t("app.name")}</span>
112 </Link>
113 <Button
114 type="button"
115 variant="ghost"
116 size="sm"
117 class="h-8 w-8 shrink-0 rounded-md px-0 text-muted-foreground hover:bg-secondary hover:text-foreground dark:text-white/70 dark:hover:bg-white/8 dark:hover:text-white"
118 aria-label={t("nav.close")}
119 onClick={() => setMobileOpen(false)}
120 >
121 <IconX class="h-4 w-4" />
122 </Button>
123 </div>
124 <div class="min-h-0 flex-1 overflow-y-auto px-1.5 py-2.5">
125 <SideNav onNavigate={() => setMobileOpen(false)} />
126 </div>
127 <SidebarAccount onLogout={logout} />
128 </aside>
129 </div>
130 </Show>
131
132 <main class="min-w-0 flex-1">
133 <Show when={auth.user() && !fullScreen()}>
134 <header class="sticky top-0 z-30 flex h-16 items-center gap-3 border-b border-border/70 bg-background px-4 sm:px-6 lg:px-8">
135 <div class="flex min-w-0 shrink-0 items-center gap-2 sm:w-52 lg:w-60">
136 <Show when={location().pathname !== "/"}>
137 <button
138 type="button"
139 onClick={() => window.history.back()}
140 class="topbar-control flex h-9 w-9 shrink-0 items-center justify-center rounded-md outline-hidden focus-visible:ring-2 focus-visible:ring-ring"
141 aria-label={t("common.back")}
142 title={t("common.back")}
143 >
144 <IconChevronLeft class="h-4 w-4" />
145 </button>
146 </Show>
147 <span class="hidden truncate text-sm font-semibold sm:block" title={routeLabel()}>{routeLabel()}</span>
148 </div>
149
150 <div class="mx-auto flex min-w-0 max-w-xl flex-1 items-center justify-center">
151 <button
152 type="button"
153 onClick={() => setCommandOpen(true)}
154 class="topbar-control flex h-9 w-full items-center justify-between gap-2.5 rounded-full px-3.5 text-sm"
155 title={t("dashboard.commandCenter")}
156 >
157 <div class="flex items-center gap-2 min-w-0">
158 <IconSearch class="h-3.5 w-3.5 shrink-0 text-muted-foreground" />
159 <span class="truncate">{t("dashboard.commandCenter")}...</span>
160 </div>
161 <kbd class="hidden shrink-0 rounded-md border border-border/80 bg-background/80 px-1.5 py-0.5 font-mono text-[10px] font-semibold text-muted-foreground sm:inline-block">
162 Ctrl/Cmd K
163 </kbd>
164 </button>
165 </div>
166
167 <div class="flex shrink-0 items-center justify-end gap-2">
168 <ShellMessagesButton />
169 <NotificationCenter />
170 <button
171 type="button"
172 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"
173 onClick={() => setCelebiOpen(true)}
174 >
175 <IconSparkles class="h-4 w-4" />
176 <span class="hidden sm:inline">{t("ai.askCelebi")}</span>
177 </button>
178 </div>
179 </header>
180 </Show>
181 <div
182 class={cn(
183 "mx-auto w-full px-4 py-6 sm:px-6 lg:px-8 lg:py-6",
184 auth.user() && !wide() && "pb-[calc(5rem+env(safe-area-inset-bottom))] lg:pb-6",
185 wide() ? "max-w-none" : "max-w-[1280px] xl:max-w-[1600px] 2xl:max-w-none",
186 )}
187 >
188 {props.children}
189 </div>
190 </main>
191 </div>
192 {/* MobileTabBar stays inside the provider — it is a shell surface, so a
193 useShellFeed() badge there must not throw. */}
194 <Show when={auth.user() && !wide()}>
195 <MobileTabBar onMenu={() => setMobileOpen(true)} />
196 </Show>
197 </ShellFeedProvider>
198 <Show when={auth.user()}>
199 <CelebiPanel open={celebiOpen()} onOpenChange={setCelebiOpen} />
200 <CommandPalette
201 open={commandOpen()}
202 onOpenChange={setCommandOpen}
203 onOpenCelebi={() => setCelebiOpen(true)}
204 onOpenProfile={() => setProfileOpen(true)}
205 />
206 <AccountProfileDialog open={profileOpen()} onOpenChange={setProfileOpen} />
207 </Show>
208 <Toaster />
209 </div>
210 );
211}