-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathSettingsSidebarNav.tsx
More file actions
76 lines (72 loc) · 2.14 KB
/
SettingsSidebarNav.tsx
File metadata and controls
76 lines (72 loc) · 2.14 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
76
import { useCallback } from "react";
import { ArrowLeftIcon } from "lucide-react";
import { useCanGoBack, useNavigate } from "@tanstack/react-router";
import {
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
SidebarSeparator,
useSidebar,
} from "../ui/sidebar";
import { SETTINGS_NAV_ITEMS, type SettingsSectionPath } from "./SettingsSidebarNav.items";
import { SettingsSidebarNavItem } from "./SettingsSidebarNavItem";
export function SettingsSidebarNav({ pathname }: { pathname: string }) {
const navigate = useNavigate();
const canGoBack = useCanGoBack();
const { isMobile, setOpenMobile } = useSidebar();
const handleSectionClick = useCallback(
(to: SettingsSectionPath) => {
if (isMobile) {
setOpenMobile(false);
}
void navigate({ to, replace: true });
},
[isMobile, navigate, setOpenMobile],
);
const handleBackClick = useCallback(() => {
if (isMobile) {
setOpenMobile(false);
}
if (canGoBack) {
window.history.back();
return;
}
void navigate({ to: "/" });
}, [canGoBack, isMobile, navigate, setOpenMobile]);
return (
<>
<SidebarContent className="overflow-x-hidden">
<SidebarGroup className="px-2 py-3">
<SidebarMenu>
{SETTINGS_NAV_ITEMS.map((item) => (
<SettingsSidebarNavItem
key={item.to}
item={item}
isActive={pathname === item.to}
onSelect={handleSectionClick}
/>
))}
</SidebarMenu>
</SidebarGroup>
</SidebarContent>
<SidebarSeparator />
<SidebarFooter className="p-2">
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton
size="sm"
className="gap-2 p-2 text-xs text-muted-foreground hover:bg-accent hover:text-foreground"
onClick={handleBackClick}
>
<ArrowLeftIcon className="size-4" />
<span>Back</span>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarFooter>
</>
);
}