Open History to see the last commit
1import type { ComponentType } from "react";
2import { ArchiveIcon, ArrowLeftIcon, Settings2Icon } from "lucide-react";
3import { useNavigate } from "@tanstack/react-router";
4
5import {
6 SidebarContent,
7 SidebarFooter,
8 SidebarGroup,
9 SidebarMenu,
10 SidebarMenuButton,
11 SidebarMenuItem,
12 SidebarSeparator,
13} from "../ui/sidebar";
14
15export type SettingsSectionPath = "/settings/general" | "/settings/archived";
16
17export const SETTINGS_NAV_ITEMS: ReadonlyArray<{
18 label: string;
19 to: SettingsSectionPath;
20 icon: ComponentType<{ className?: string }>;
21}> = [
22 { label: "General", to: "/settings/general", icon: Settings2Icon },
23 { label: "Archive", to: "/settings/archived", icon: ArchiveIcon },
24];
25
26export function SettingsSidebarNav({ pathname }: { pathname: string }) {
27 const navigate = useNavigate();
28
29 return (
30 <>
31 <SidebarContent className="overflow-x-hidden">
32 <SidebarGroup className="px-2 py-3">
33 <SidebarMenu>
34 {SETTINGS_NAV_ITEMS.map((item) => {
35 const Icon = item.icon;
36 const isActive = pathname === item.to;
37 return (
38 <SidebarMenuItem key={item.to}>
39 <SidebarMenuButton
40 size="sm"
41 isActive={isActive}
42 className={
43 isActive
44 ? "gap-2 px-2 py-2 text-left text-xs text-foreground"
45 : "gap-2 px-2 py-2 text-left text-xs text-muted-foreground hover:text-foreground/80"
46 }
47 onClick={() => void navigate({ to: item.to, replace: true })}
48 >
49 <Icon
50 className={
51 isActive
52 ? "size-4 shrink-0 text-foreground"
53 : "size-4 shrink-0 text-muted-foreground"
54 }
55 />
56 <span className="truncate">{item.label}</span>
57 </SidebarMenuButton>
58 </SidebarMenuItem>
59 );
60 })}
61 </SidebarMenu>
62 </SidebarGroup>
63 </SidebarContent>
64
65 <SidebarSeparator />
66 <SidebarFooter className="p-2">
67 <SidebarMenu>
68 <SidebarMenuItem>
69 <SidebarMenuButton
70 size="sm"
71 className="gap-2 px-2 py-2 text-xs text-muted-foreground hover:bg-accent hover:text-foreground"
72 onClick={() => window.history.back()}
73 >
74 <ArrowLeftIcon className="size-4" />
75 <span>Back</span>
76 </SidebarMenuButton>
77 </SidebarMenuItem>
78 </SidebarMenu>
79 </SidebarFooter>
80 </>
81 );
82}