Open History to see the last commit
1import { useCallback, type ComponentType } from "react";
2import {
3 ArchiveIcon,
4 ArrowLeftIcon,
5 BotIcon,
6 FlaskConicalIcon,
7 GitBranchIcon,
8 KeyboardIcon,
9 Link2Icon,
10 Settings2Icon,
11} from "lucide-react";
12import { useCanGoBack, useNavigate } from "@tanstack/react-router";
13
14import {
15 SidebarContent,
16 SidebarFooter,
17 SidebarGroup,
18 SidebarMenu,
19 SidebarMenuButton,
20 SidebarMenuItem,
21 useSidebar,
22} from "../ui/sidebar";
23import { T3ConnectSidebarAvatar, T3ConnectSidebarSignIn } from "../clerk/T3ConnectSidebarSignIn";
24
25export type SettingsSectionPath =
26 | "/settings/general"
27 | "/settings/keybindings"
28 | "/settings/providers"
29 | "/settings/source-control"
30 | "/settings/connections"
31 | "/settings/beta"
32 | "/settings/archived";
33
34export const SETTINGS_NAV_ITEMS: ReadonlyArray<{
35 label: string;
36 to: SettingsSectionPath;
37 icon: ComponentType<{ className?: string }>;
38}> = [
39 { label: "General", to: "/settings/general", icon: Settings2Icon },
40 { label: "Keybindings", to: "/settings/keybindings", icon: KeyboardIcon },
41 { label: "Providers", to: "/settings/providers", icon: BotIcon },
42 { label: "Source Control", to: "/settings/source-control", icon: GitBranchIcon },
43 { label: "Connections", to: "/settings/connections", icon: Link2Icon },
44 { label: "Beta", to: "/settings/beta", icon: FlaskConicalIcon },
45 { label: "Archive", to: "/settings/archived", icon: ArchiveIcon },
46];
47
48export function SettingsSidebarNav({ pathname }: { pathname: string }) {
49 const navigate = useNavigate();
50 const canGoBack = useCanGoBack();
51 const { isMobile, setOpenMobile } = useSidebar();
52 const handleSectionClick = useCallback(
53 (to: SettingsSectionPath) => {
54 if (isMobile) {
55 setOpenMobile(false);
56 }
57 void navigate({ to, replace: true });
58 },
59 [isMobile, navigate, setOpenMobile],
60 );
61 const handleBackClick = useCallback(() => {
62 if (isMobile) {
63 setOpenMobile(false);
64 }
65 if (canGoBack) {
66 window.history.back();
67 return;
68 }
69 void navigate({ to: "/" });
70 }, [canGoBack, isMobile, navigate, setOpenMobile]);
71
72 return (
73 <>
74 <SidebarContent className="overflow-x-hidden">
75 <SidebarGroup className="px-2 py-3">
76 <SidebarMenu>
77 {SETTINGS_NAV_ITEMS.map((item) => {
78 const Icon = item.icon;
79 const isActive = pathname === item.to;
80 return (
81 <SidebarMenuItem key={item.to}>
82 <SidebarMenuButton
83 size="sm"
84 isActive={isActive}
85 className={
86 isActive
87 ? "h-8 items-center gap-2 rounded-md bg-sidebar-row-active px-2 py-1.5 text-left text-sm font-medium text-sidebar-foreground"
88 : "h-8 items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm font-medium text-sidebar-muted-foreground/80 hover:bg-sidebar-row-hover hover:text-sidebar-foreground"
89 }
90 onClick={() => handleSectionClick(item.to)}
91 >
92 <Icon
93 className={
94 isActive
95 ? "size-4 shrink-0 text-sidebar-foreground"
96 : "size-4 shrink-0 text-sidebar-muted-foreground/60"
97 }
98 />
99 <span className="truncate">{item.label}</span>
100 </SidebarMenuButton>
101 </SidebarMenuItem>
102 );
103 })}
104 </SidebarMenu>
105 </SidebarGroup>
106 </SidebarContent>
107 <SidebarFooter className="p-2">
108 <T3ConnectSidebarSignIn />
109 <div className="grid grid-cols-[minmax(0,1fr)_auto] items-center gap-1">
110 <SidebarMenu className="min-w-0">
111 <SidebarMenuItem>
112 <SidebarMenuButton
113 size="sm"
114 className="h-8 items-center gap-2 rounded-md px-2 py-1.5 text-sm font-medium text-sidebar-muted-foreground/80 hover:bg-sidebar-row-hover hover:text-sidebar-foreground"
115 onClick={handleBackClick}
116 >
117 <ArrowLeftIcon className="size-4" />
118 <span>Back</span>
119 </SidebarMenuButton>
120 </SidebarMenuItem>
121 </SidebarMenu>
122 <T3ConnectSidebarAvatar />
123 </div>
124 </SidebarFooter>
125 </>
126 );
127}