Open History to see the last commit
1import { useEffect, type ReactNode } from "react";
2import { useNavigate } from "@tanstack/react-router";
3
4import ThreadSidebar from "./Sidebar";
5import { Sidebar, SidebarProvider, SidebarRail } from "./ui/sidebar";
6
7const THREAD_SIDEBAR_WIDTH_STORAGE_KEY = "chat_thread_sidebar_width";
8const THREAD_SIDEBAR_MIN_WIDTH = 13 * 16;
9const THREAD_MAIN_CONTENT_MIN_WIDTH = 40 * 16;
10
11export function AppSidebarLayout({ children }: { children: ReactNode }) {
12 const navigate = useNavigate();
13
14 useEffect(() => {
15 const onMenuAction = window.desktopBridge?.onMenuAction;
16 if (typeof onMenuAction !== "function") {
17 return;
18 }
19
20 const unsubscribe = onMenuAction((action) => {
21 if (action !== "open-settings") return;
22 void navigate({ to: "/settings" });
23 });
24
25 return () => {
26 unsubscribe?.();
27 };
28 }, [navigate]);
29
30 return (
31 <SidebarProvider defaultOpen>
32 <Sidebar
33 side="left"
34 collapsible="offcanvas"
35 className="border-r border-border bg-card text-foreground"
36 resizable={{
37 minWidth: THREAD_SIDEBAR_MIN_WIDTH,
38 shouldAcceptWidth: ({ nextWidth, wrapper }) =>
39 wrapper.clientWidth - nextWidth >= THREAD_MAIN_CONTENT_MIN_WIDTH,
40 storageKey: THREAD_SIDEBAR_WIDTH_STORAGE_KEY,
41 }}
42 >
43 <ThreadSidebar />
44 <SidebarRail />
45 </Sidebar>
46 {children}
47 </SidebarProvider>
48 );
49}