forked from pingdotgg/t3code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppSidebarLayout.tsx
More file actions
75 lines (66 loc) · 2.22 KB
/
AppSidebarLayout.tsx
File metadata and controls
75 lines (66 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { useEffect, type ReactNode } from "react";
import { useNavigate } from "@tanstack/react-router";
import ThreadSidebar from "./Sidebar";
import { Sidebar, SidebarProvider, SidebarRail } from "./ui/sidebar";
import {
clearShortcutModifierState,
syncShortcutModifierStateFromKeyboardEvent,
} from "../shortcutModifierState";
const THREAD_SIDEBAR_WIDTH_STORAGE_KEY = "chat_thread_sidebar_width";
const THREAD_SIDEBAR_MIN_WIDTH = 13 * 16;
const THREAD_MAIN_CONTENT_MIN_WIDTH = 40 * 16;
export function AppSidebarLayout({ children }: { children: ReactNode }) {
const navigate = useNavigate();
useEffect(() => {
const onWindowKeyDown = (event: KeyboardEvent) => {
syncShortcutModifierStateFromKeyboardEvent(event);
};
const onWindowKeyUp = (event: KeyboardEvent) => {
syncShortcutModifierStateFromKeyboardEvent(event);
};
const onWindowBlur = () => {
clearShortcutModifierState();
};
window.addEventListener("keydown", onWindowKeyDown, true);
window.addEventListener("keyup", onWindowKeyUp, true);
window.addEventListener("blur", onWindowBlur);
return () => {
window.removeEventListener("keydown", onWindowKeyDown, true);
window.removeEventListener("keyup", onWindowKeyUp, true);
window.removeEventListener("blur", onWindowBlur);
};
}, []);
useEffect(() => {
const onMenuAction = window.desktopBridge?.onMenuAction;
if (typeof onMenuAction !== "function") {
return;
}
const unsubscribe = onMenuAction((action) => {
if (action === "open-settings") {
void navigate({ to: "/settings" });
}
});
return () => {
unsubscribe?.();
};
}, [navigate]);
return (
<SidebarProvider defaultOpen>
<Sidebar
side="left"
collapsible="offcanvas"
className="border-r border-border bg-card text-foreground"
resizable={{
minWidth: THREAD_SIDEBAR_MIN_WIDTH,
shouldAcceptWidth: ({ nextWidth, wrapper }) =>
wrapper.clientWidth - nextWidth >= THREAD_MAIN_CONTENT_MIN_WIDTH,
storageKey: THREAD_SIDEBAR_WIDTH_STORAGE_KEY,
}}
>
<ThreadSidebar />
<SidebarRail />
</Sidebar>
{children}
</SidebarProvider>
);
}