Skip to content
File

Blob: src/client/components/layouts/standalone-layout.tsx

typescript42 lines
1import { useCallback, useState } from "react";
2import { Outlet } from "@tanstack/react-router";
3import { STORAGE_KEYS } from "@/client/lib/constants";
4import { Header } from "@/client/components/header";
5import { Footer } from "@/client/components/footer";
6import { Banners } from "@/client/components/ui/banners";
7import { readStorageString, writeStorageString } from "@/client/lib/storage";
8import { selectHasLocalSession, useAuthStore } from "@/client/stores/auth-store";
9 
10const NARROW_SHELL_CONTENT_CLASS = "mx-auto w-full max-w-7xl";
11const NARROW_SHELL_ROW_CLASS = `${NARROW_SHELL_CONTENT_CLASS} border-l border-zinc-800/60`;
12 
13export function StandaloneLayout() {
14 const hasLocalSession = useAuthStore(selectHasLocalSession);
15 const [storedLayout, setStoredLayout] = useState(() => readStorageString(STORAGE_KEYS.LAYOUT));
16 const expanded = hasLocalSession && storedLayout === "expanded";
17 
18 const toggleLayout = useCallback(() => {
19 const next = expanded ? "default" : "expanded";
20 writeStorageString(STORAGE_KEYS.LAYOUT, next);
21 setStoredLayout(next);
22 }, [expanded]);
23 return (
24 <div className="flex h-screen flex-col">
25 <a
26 href="#main-content"
27 className="sr-only focus:not-sr-only focus:fixed focus:left-4 focus:top-4 focus:z-[200] focus:rounded-lg focus:bg-zinc-800 focus:px-4 focus:py-2 focus:text-accent-400 focus:ring-2 focus:ring-accent-500/50"
28 >
29 Skip to content
30 </a>
31 <Header expanded={expanded} onToggleLayout={toggleLayout} />
32 <Banners />
33 <div className={`flex flex-1 overflow-hidden ${expanded ? "" : NARROW_SHELL_ROW_CLASS}`}>
34 <main id="main-content" tabIndex={-1} className="flex-1 overflow-y-auto outline-none">
35 <Outlet />
36 </main>
37 </div>
38 <Footer expanded={expanded} />
39 </div>
40 );
41}