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 Props { /** * The chats, whose sidebar is a column beside the panel that collapses off the window's edge, or * settings and admin, whose nav sits inside the panel beside the section. */ kind: 'chats' | 'settings' /** What the sidebar holds, such as the chat list or links to each section. */ 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. */ export function SidebarLayout(props: Props) { 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]) const backdrop = sidebar.drawerOpen && (