forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBd962efeBurak Boduroğlu4 months ago146 commits

app-shell.tsx133 lines, 5.5 KiBHistoryRawDownload
1import type { ParentProps } from "solid-js";
2import { Link, useLocation, useNavigate } from "@tanstack/solid-router";
3import { Show, createSignal } from "solid-js";
4import { MobileTabBar } from "@/components/layout/mobile-tab-bar";
5import { NavBar } from "@/components/layout/nav-bar";
6import { SideNav } from "@/components/layout/side-nav";
7import { SidebarAccount } from "@/components/layout/sidebar-account";
8import { Button } from "@/components/ui/button";
9import { IconPanelLeft, IconX } from "@/components/ui/icons";
10import { useAuth } from "@/stores/auth-context";
11import { usePreferences, useT } from "@/stores/preferences-context";
12import { cn } from "@/lib/cn";
13
14const SIDEBAR_EXPANDED = "w-56";
15const SIDEBAR_COLLAPSED = "w-16";
16
17export function AppShell(props: ParentProps) {
18 const auth = useAuth();
19 const prefs = usePreferences();
20 const t = useT();
21 const navigate = useNavigate();
22 const [mobileOpen, setMobileOpen] = createSignal(false);
23 const collapsed = () => prefs.sidebarCollapsed();
24 const location = useLocation();
25 const wide = () => location().pathname.startsWith("/exam-room/");
26 const logout = async () => {
27 await auth.logout();
28 void navigate({ to: "/login" });
29 };
30
31 return (
32 <div class="min-h-screen bg-background text-foreground">
33 <Show when={!auth.user()}>
34 <NavBar />
35 </Show>
36 <div class="flex w-full">
37 <Show when={auth.user()}>
38 <aside
39 class={cn(
40 "sticky top-0 z-30 hidden h-screen shrink-0 border-r border-border/80 bg-sidebar shadow-[inset_-1px_0_0_hsl(var(--border)/0.45)] transition-[width] duration-150 ease-out lg:flex lg:flex-col",
41 collapsed() ? SIDEBAR_COLLAPSED : SIDEBAR_EXPANDED,
42 )}
43 >
44 <div
45 class={cn(
46 "flex shrink-0 items-center gap-2 border-b border-border/70",
47 collapsed() ? "h-auto flex-col justify-center gap-1.5 px-2 py-2" : "h-14 px-2",
48 )}
49 >
50 <Link
51 to="/"
52 class={cn("flex min-w-0 items-center gap-2", collapsed() ? "justify-center" : "flex-1")}
53 title={t("app.name")}
54 >
55 <span class="flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-primary text-xs font-bold text-primary-foreground shadow-sm">
56 H
57 </span>
58 <Show when={!collapsed()}>
59 <span class="truncate font-display text-base font-semibold tracking-tight">{t("app.name")}</span>
60 </Show>
61 </Link>
62 <Button
63 type="button"
64 variant="ghost"
65 size="sm"
66 class="h-8 w-8 shrink-0 justify-center rounded-lg px-0 text-muted-foreground hover:bg-muted/70 hover:text-foreground"
67 aria-label={collapsed() ? t("nav.expand") : t("nav.collapse")}
68 title={collapsed() ? t("nav.expand") : t("nav.collapse")}
69 onClick={() => prefs.toggleSidebar()}
70 >
71 <IconPanelLeft class={cn("h-4 w-4 shrink-0 transition-transform duration-150", collapsed() && "scale-x-[-1]")} />
72 </Button>
73 </div>
74
75 <div class="min-h-0 flex-1 overflow-y-auto overflow-x-hidden pt-4 pb-1">
76 <SideNav collapsed={collapsed()} />
77 </div>
78
79 <SidebarAccount collapsed={collapsed()} onLogout={logout} />
80 </aside>
81 </Show>
82
83 <Show when={mobileOpen() && auth.user()}>
84 <div class="fixed inset-0 z-50 lg:hidden">
85 <button
86 type="button"
87 class="absolute inset-0 bg-black/60 backdrop-blur-sm"
88 aria-label={t("nav.close")}
89 onClick={() => setMobileOpen(false)}
90 />
91 <aside class="absolute inset-y-0 left-0 flex w-72 max-w-[85vw] flex-col border-r border-border bg-sidebar shadow-soft">
92 <div class="flex h-14 shrink-0 items-center justify-between gap-2 border-b border-border px-3">
93 <Link to="/" class="flex min-w-0 items-center gap-2" onClick={() => setMobileOpen(false)}>
94 <span class="flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-primary text-xs font-bold text-primary-foreground">H</span>
95 <span class="truncate font-display text-base font-semibold">{t("app.name")}</span>
96 </Link>
97 <Button
98 type="button"
99 variant="ghost"
100 size="sm"
101 class="h-8 w-8 shrink-0 px-0"
102 aria-label={t("nav.close")}
103 onClick={() => setMobileOpen(false)}
104 >
105 <IconX class="h-4 w-4" />
106 </Button>
107 </div>
108 <div class="min-h-0 flex-1 overflow-y-auto py-3">
109 <SideNav onNavigate={() => setMobileOpen(false)} />
110 </div>
111 <SidebarAccount onLogout={logout} />
112 </aside>
113 </div>
114 </Show>
115
116 <main class="min-w-0 flex-1">
117 <div
118 class={cn(
119 "mx-auto w-full px-4 py-6 sm:px-6 lg:px-8 lg:py-5",
120 auth.user() && !wide() && "pb-24 lg:pb-5",
121 wide() ? "max-w-none" : "max-w-[1200px]",
122 )}
123 >
124 {props.children}
125 </div>
126 </main>
127 </div>
128 <Show when={auth.user() && !wide()}>
129 <MobileTabBar onMenu={() => setMobileOpen(true)} />
130 </Show>
131 </div>
132 );
133}