import { useLoaderData, useLocation } from '@tanstack/react-router' import { type ReactNode, useEffect } from 'react' import { cn } from './cn.ts' import { Logo } from './ui/Logo.tsx' import { SidebarToggle } from './ui/SidebarToggle.tsx' import { useSidebar } from './useSidebar.ts' interface SettingsProps { /** Links to each section. */ nav?: ReactNode children?: ReactNode } interface ChatsProps { /** The chat list. */ nav?: ReactNode /** The page's frame while its code loads, its nav a skeleton of what will fill it. */ frame?: boolean children?: ReactNode } /* * The sidebar, after Linear's: dense one-line rows of small text on the frame. On a narrow screen it * is a drawer over the page, closed until opened, which closes again once a link in it is followed. */ /** The narrow screen's drawer, closed on each navigation. */ function useDrawer() { const sidebar = useSidebar() const pathname = useLocation({ select: (location) => location.pathname }) const { closeDrawer } = sidebar // biome-ignore lint/correctness/useExhaustiveDependencies: closing follows each navigation. useEffect(() => closeDrawer(), [pathname]) return sidebar } interface BackdropProps { open: boolean onClose: () => void } /** The dimmed page behind an open drawer, which closes it when pressed. */ function Backdrop(props: BackdropProps) { if (!props.open) return null return (