hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB4e0a329Burak Boduroğlu2 months ago537 commits
| 1 | import { Show, createEffect, createMemo, createSignal, type ParentProps } from "solid-js"; |
| 2 | import { Link, useLocation, useNavigate } from "@tanstack/solid-router"; |
| 3 | import { LogoMark } from "@/components/brand/logo-mark"; |
| 4 | import { AccountProfileDialog } from "@/components/users/account-profile-dialog"; |
| 5 | import { CelebiPanel } from "@/components/layout/celebi-panel"; |
| 6 | import { CommandPalette } from "@/components/layout/command-palette"; |
| 7 | import { MobileTabBar } from "@/components/layout/mobile-tab-bar"; |
| 8 | import { NavBar } from "@/components/layout/nav-bar"; |
| 9 | import { NetworkStatusBanner } from "@/components/layout/network-status-banner"; |
| 10 | import { NotificationCenter } from "@/components/layout/notification-center"; |
| 11 | import { routeLabelKey } from "@/components/layout/nav-items"; |
| 12 | import { ShellMessagesButton } from "@/components/layout/shell-messages-button"; |
| 13 | import { MobileNavSheet } from "@/components/layout/mobile-nav-sheet"; |
| 14 | import { SideNav } from "@/components/layout/side-nav"; |
| 15 | import { SidebarAccount } from "@/components/layout/sidebar-account"; |
| 16 | import { IconChevronLeft, IconSparkles } from "@/components/ui/icons"; |
| 17 | import { Toaster } from "@/components/ui/toast"; |
| 18 | import { useAuth } from "@/stores/auth-context"; |
| 19 | import { useModules } from "@/stores/modules-context"; |
| 20 | import { commandPaletteOpen, openCommandPalette, setCommandPaletteOpen } from "@/stores/command-palette"; |
| 21 | import { ShellFeedProvider } from "@/stores/shell-feed-context"; |
| 22 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| 23 | import { cn } from "@/lib/cn"; |
| 24 | |
| 25 | const SIDEBAR_EXPANDED = "w-[260px]"; |
| 26 | const SIDEBAR_COLLAPSED = "w-24"; |
| 27 | |
| 28 | export function AppShell(props: ParentProps) { |
| 29 | const auth = useAuth(); |
| 30 | const prefs = usePreferences(); |
| 31 | const t = useT(); |
| 32 | const modules = useModules(); |
| 33 | const navigate = useNavigate(); |
| 34 | const [mobileOpen, setMobileOpen] = createSignal(false); |
| 35 | const [celebiOpen, setCelebiOpen] = createSignal(false); |
| 36 | const [profileOpen, setProfileOpen] = createSignal(false); |
| 37 | const collapsed = () => prefs.sidebarCollapsed(); |
| 38 | const location = useLocation(); |
| 39 | const wide = () => location().pathname.startsWith("/exam-room/") || location().searchStr.includes("answerUser=") || location().pathname === "/messages"; |
| 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 | <Show when={!auth.user()}> |
| 59 | <NavBar /> |
| 60 | </Show> |
| 61 | <ShellFeedProvider> |
| 62 | <div class="flex w-full"> |
| 63 | <Show when={auth.user() && !fullScreen()}> |
| 64 | <aside |
| 65 | class={cn( |
| 66 | "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", |
| 67 | collapsed() ? SIDEBAR_COLLAPSED : SIDEBAR_EXPANDED, |
| 68 | )} |
| 69 | > |
| 70 | <div |
| 71 | class={cn( |
| 72 | "flex h-[45px] shrink-0 items-center border-b border-border/70", |
| 73 | collapsed() ? "justify-center px-2" : "px-3", |
| 74 | )} |
| 75 | > |
| 76 | <Link |
| 77 | to="/" |
| 78 | class={cn("flex min-w-0 items-center gap-2.5", collapsed() ? "justify-center" : "flex-1")} |
| 79 | title={t("app.name")} |
| 80 | > |
| 81 | <span class="flex h-8 w-8 shrink-0 items-center justify-center text-foreground"> |
| 82 | <LogoMark size={28} /> |
| 83 | </span> |
| 84 | <Show when={!collapsed()}> |
| 85 | <span class="truncate text-base font-semibold tracking-tight text-foreground dark:text-white 2xl:text-lg">{t("app.name")}</span> |
| 86 | </Show> |
| 87 | </Link> |
| 88 | </div> |
| 89 | |
| 90 | <div class="min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-1.5 py-2.5"> |
| 91 | <SideNav |
| 92 | collapsed={collapsed()} |
| 93 | onOpenCelebi={() => setCelebiOpen(true)} |
| 94 | onOpenProfile={() => setProfileOpen(true)} |
| 95 | /> |
| 96 | </div> |
| 97 | |
| 98 | <SidebarAccount collapsed={collapsed()} onLogout={logout} /> |
| 99 | |
| 100 | {/* Collapse toggle rides the corner where the sidebar's right edge |
| 101 | meets the header's bottom border. */} |
| 102 | <button |
| 103 | type="button" |
| 104 | class="absolute right-0 top-[45px] z-10 flex h-6 w-6 -translate-y-1/2 translate-x-1/2 items-center justify-center rounded-full 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" |
| 105 | aria-label={collapsed() ? t("nav.expand") : t("nav.collapse")} |
| 106 | aria-expanded={!collapsed()} |
| 107 | title={collapsed() ? t("nav.expand") : t("nav.collapse")} |
| 108 | onClick={() => prefs.toggleSidebar()} |
| 109 | > |
| 110 | <IconChevronLeft class={cn("h-3.5 w-3.5 transition-transform duration-200", collapsed() && "rotate-180")} /> |
| 111 | </button> |
| 112 | |
| 113 | </aside> |
| 114 | </Show> |
| 115 | |
| 116 | <Show when={auth.user()}> |
| 117 | <MobileNavSheet |
| 118 | open={mobileOpen()} |
| 119 | onClose={() => setMobileOpen(false)} |
| 120 | onLogout={logout} |
| 121 | onOpenCelebi={() => setCelebiOpen(true)} |
| 122 | onOpenProfile={() => setProfileOpen(true)} |
| 123 | /> |
| 124 | </Show> |
| 125 | |
| 126 | <main class="min-w-0 flex-1"> |
| 127 | <Show when={auth.user() && !fullScreen()}> |
| 128 | <header class="sticky top-[env(safe-area-inset-top)] z-30 flex h-[45px] items-center gap-3 border-b border-border/70 bg-background px-4 sm:px-6 lg:px-4"> |
| 129 | <div class="flex min-w-0 shrink-0 items-center gap-2 sm:w-52 lg:w-[260px]"> |
| 130 | <Show when={location().pathname !== "/"}> |
| 131 | <button |
| 132 | type="button" |
| 133 | onClick={() => window.history.back()} |
| 134 | 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" |
| 135 | aria-label={t("common.back")} |
| 136 | title={t("common.back")} |
| 137 | > |
| 138 | <IconChevronLeft class="h-4 w-4" /> |
| 139 | </button> |
| 140 | </Show> |
| 141 | <span class="hidden truncate text-sm font-semibold sm:block" title={routeLabel()}>{routeLabel()}</span> |
| 142 | </div> |
| 143 | |
| 144 | <div class="min-w-0 flex-1" /> |
| 145 | |
| 146 | <div class="flex shrink-0 items-center justify-end gap-2"> |
| 147 | <ShellMessagesButton /> |
| 148 | <NotificationCenter /> |
| 149 | <Show when={modules.isEnabled("chatbot")}> |
| 150 | <button |
| 151 | type="button" |
| 152 | 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" |
| 153 | aria-label={t("ai.askCelebi")} |
| 154 | title={t("ai.askCelebi")} |
| 155 | onClick={() => setCelebiOpen(true)} |
| 156 | > |
| 157 | <IconSparkles class="h-4 w-4" /> |
| 158 | <span>{t("ai.askCelebi")}</span> |
| 159 | </button> |
| 160 | </Show> |
| 161 | </div> |
| 162 | </header> |
| 163 | </Show> |
| 164 | <Show when={auth.user() && !fullScreen()}> |
| 165 | <NetworkStatusBanner /> |
| 166 | </Show> |
| 167 | <div |
| 168 | class={cn( |
| 169 | "mx-auto w-full px-4 py-6 sm:px-6 lg:px-10 lg:py-6", |
| 170 | auth.user() && !fullScreen() && "pb-[calc(3.5rem+max(env(safe-area-inset-bottom),var(--android-nav-inset,0px)))] lg:pb-6", |
| 171 | wide() ? "max-w-none" : "max-w-[1180px]", |
| 172 | )} |
| 173 | > |
| 174 | {props.children} |
| 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={celebiOpen()} onOpenChange={setCelebiOpen} /> |
| 186 | <CommandPalette |
| 187 | open={commandPaletteOpen()} |
| 188 | onOpenChange={setCommandPaletteOpen} |
| 189 | onOpenCelebi={() => setCelebiOpen(true)} |
| 190 | onOpenProfile={() => setProfileOpen(true)} |
| 191 | /> |
| 192 | <AccountProfileDialog open={profileOpen()} onOpenChange={setProfileOpen} /> |
| 193 | </Show> |
| 194 | <Toaster /> |
| 195 | </div> |
| 196 | ); |
| 197 | } |