Open History to see the last commit
1import { Link } from "@tanstack/react-router";
2import { ChartColumn, ChevronRight, Folder, PanelLeft, Trash } from "lucide-react";
3import type { ReactNode } from "react";
4
5import { useAccount, useFolders, useNoteCounts } from "@/data/notes-data";
6
7import { AccountAvatar, QuickNotesIcon, SharedIcon } from "../icons";
8import { useNotesLayout } from "../notes-layout";
9import { MacCircleButton, MacColumnHeader } from "./controls";
10
11export function SidebarToggle() {
12 const { toggleSidebar, sidebarVisible } = useNotesLayout();
13 return (
14 <MacCircleButton
15 aria-label={sidebarVisible ? "Hide sidebar" : "Show sidebar"}
16 aria-pressed={sidebarVisible}
17 onClick={toggleSidebar}
18 >
19 <PanelLeft />
20 </MacCircleButton>
21 );
22}
23
24export function MacSidebar() {
25 const folders = useFolders();
26 const counts = useNoteCounts();
27 const account = useAccount();
28
29 const quickNotes = folders.find((folder) => folder.role === "quick-notes");
30 const iCloudFolders = folders.filter((folder) => folder.role !== "quick-notes");
31
32 return (
33 <nav
34 aria-label="Folders"
35 className="flex w-[208px] shrink-0 flex-col border-r border-mac-column-border bg-mac-sidebar"
36 >
37 <MacColumnHeader>
38 <SidebarToggle />
39 </MacColumnHeader>
40
41 <div className="notes-scroll min-h-0 flex-1 overflow-y-auto px-2.5 pb-3">
42 {quickNotes && (
43 <SidebarLink
44 folderId={quickNotes.id}
45 icon={<QuickNotesIcon />}
46 label={quickNotes.name}
47 count={counts[quickNotes.id]}
48 />
49 )}
50 <SidebarLink folderId="shared" icon={<SharedIcon />} label="Shared" count={counts.shared} />
51
52 <SidebarGroupLabel>iCloud</SidebarGroupLabel>
53 <SidebarLink folderId="all" icon={<FolderIcon />} label="All iCloud" count={counts.all} />
54 {iCloudFolders.map((folder) => (
55 <SidebarLink
56 key={folder.id}
57 folderId={folder.id}
58 icon={<FolderIcon />}
59 label={folder.name}
60 count={counts[folder.id]}
61 />
62 ))}
63 <SidebarLink
64 folderId="recently-deleted"
65 icon={<Trash className="size-[17px] stroke-[1.5] text-mac-icon" />}
66 label="Recently Deleted"
67 count={counts["recently-deleted"]}
68 />
69
70 <SidebarGroupLabel collapsed>Tags</SidebarGroupLabel>
71 </div>
72
73 <div className="space-y-0.5 border-t border-mac-column-border px-2.5 py-2">
74 <Link to="/analytics" className={rowClassName}>
75 <ChartColumn className="size-[17px] stroke-[1.5] text-mac-icon" />
76 <span className="flex-1 truncate">Analytics</span>
77 </Link>
78 <Link to="/settings" className={`${rowClassName} h-auto py-1.5`}>
79 <AccountAvatar name={account.name} />
80 <span className="min-w-0 flex-1 leading-tight">
81 <span className="block truncate font-medium">{account.name}</span>
82 <span className="block truncate text-[11px] text-mac-text-secondary">
83 {account.email}
84 </span>
85 </span>
86 </Link>
87 </div>
88 </nav>
89 );
90}
91
92const rowClassName =
93 "flex h-[30px] items-center gap-2 rounded-[7px] px-2 text-[13px] text-mac-text outline-none focus-visible:ring-2 focus-visible:ring-notes-accent/60 data-[status=active]:bg-mac-folder-selected";
94
95function SidebarLink({
96 folderId,
97 icon,
98 label,
99 count,
100}: {
101 folderId: string;
102 icon: ReactNode;
103 label: string;
104 count: number | undefined;
105}) {
106 return (
107 <Link to="/folders/$folderId" params={{ folderId }} className={rowClassName}>
108 {icon}
109 <span className="flex-1 truncate">{label}</span>
110 <span className="text-[12px] text-mac-text-secondary tabular-nums">{count ?? 0}</span>
111 </Link>
112 );
113}
114
115function SidebarGroupLabel({ children, collapsed }: { children: ReactNode; collapsed?: boolean }) {
116 return (
117 <div className="group flex items-center px-2 pt-4 pb-1 text-[11px] font-semibold text-mac-text-secondary">
118 <span className="flex-1">{children}</span>
119 {collapsed && (
120 <ChevronRight className="size-3 opacity-0 transition-opacity group-hover:opacity-100" />
121 )}
122 </div>
123 );
124}
125
126function FolderIcon() {
127 return <Folder className="size-[17px] shrink-0 stroke-[1.5] text-mac-icon" aria-hidden />;
128}