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