"use client"; import { useCallback, useEffect, useState } from "react"; import { usePathname, useRouter } from "next/navigation"; import { MenuIcon, XIcon } from "lucide-react"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import type { ChatSummary } from "@/src/store/chats"; /** * The app's primary navigation: a hamburger that opens the session list. * Sessions only — settings and other chrome will dock here later. * Renders the toggle button (sits in the page header) plus the slide-over. */ export function SessionDrawer() { const [open, setOpen] = useState(false); const [chats, setChats] = useState(null); const router = useRouter(); const pathname = usePathname(); const load = useCallback(async () => { try { const res = await fetch("/api/chats", { cache: "no-store" }); const data = (await res.json()) as { chats: ChatSummary[] }; setChats(data.chats); } catch { setChats([]); } }, []); useEffect(() => { if (open) void load(); }, [open, load]); // ESC closes; body scroll locks while open. useEffect(() => { if (!open) return; const onKey = (e: KeyboardEvent) => e.key === "Escape" && setOpen(false); document.addEventListener("keydown", onKey); document.body.style.overflow = "hidden"; return () => { document.removeEventListener("keydown", onKey); document.body.style.overflow = ""; }; }, [open]); const go = (href: string) => { setOpen(false); router.push(href); }; return ( <> {/* backdrop */}
setOpen(false)} /> {/* panel */} ); }