Open History to see the last commit
1import { Link } from "@tanstack/react-router";
2import { ChartColumn, Folder, FolderPlus, Pencil, Trash } from "lucide-react";
3import { useState } from "react";
4import type { ReactNode } from "react";
5
6import { useRevealForSpotlight } from "@/components/spotlight/spotlight-reveal";
7import { useAccount, useFolders, useNoteCounts } from "@/db/queries";
8import type { Folder as FolderRecord } from "@/db/schema";
9import { reportAction } from "@/lib/app-actions";
10import { isSmartFolderId } from "@/lib/notes/folder-views";
11import { cn } from "@/lib/utils";
12
13import { AccountAvatar, QuickNotesIcon, SharedIcon } from "../icons";
14import { canRenameFolder, RenameFolderDialog } from "../rename-folder-dialog";
15import { useComposeNote } from "../use-compose-note";
16import {
17 GlassCircle,
18 GlassPill,
19 InsetCard,
20 InsetRow,
21 IosScreen,
22 LargeTitle,
23 RowChevron,
24 SearchAndCompose,
25 SectionHeader,
26} from "./ui";
27
28export function IosFoldersScreen() {
29 const folders = useFolders();
30 const counts = useNoteCounts();
31 const account = useAccount();
32 const [iCloudOpen, setICloudOpen] = useState(true);
33 useRevealForSpotlight("folder-counts", () => setICloudOpen(true));
34 const [editing, setEditing] = useState(false);
35 const [renaming, setRenaming] = useState<FolderRecord | null>(null);
36 const composeNote = useComposeNote();
37
38 const quickNotes = folders.find((folder) => folder.role === "quick-notes");
39 const iCloudFolders = folders.filter((folder) => folder.role !== "quick-notes");
40
41 return (
42 <IosScreen
43 trailing={
44 <>
45 <GlassCircle aria-label="New folder">
46 <FolderPlus />
47 </GlassCircle>
48 <GlassPill className={cn("p-0", editing && "bg-notes-accent text-black")}>
49 <button
50 type="button"
51 aria-pressed={editing}
52 onClick={() => setEditing((on) => !on)}
53 className="h-full rounded-full px-4 text-[17px] font-medium"
54 >
55 {editing ? "Done" : "Edit"}
56 </button>
57 </GlassPill>
58 </>
59 }
60 bottom={<SearchAndCompose onCompose={composeNote} />}
61 >
62 <LargeTitle title="Folders" />
63
64 <InsetCard>
65 {quickNotes && (
66 <InsetRow first separatorInset={58}>
67 <FolderRow
68 folderId={quickNotes.id}
69 icon={<QuickNotesIcon className="size-[30px] rounded-[8px]" />}
70 name={quickNotes.name}
71 count={counts[quickNotes.id]}
72 />
73 </InsetRow>
74 )}
75 <InsetRow first={!quickNotes} separatorInset={58}>
76 <FolderRow
77 folderId="shared"
78 icon={<SharedIcon className="size-[30px] rounded-[8px]" />}
79 name="Shared"
80 count={counts.shared}
81 />
82 </InsetRow>
83 </InsetCard>
84
85 <SectionHeader chevron open={iCloudOpen} onToggle={() => setICloudOpen((open) => !open)}>
86 iCloud
87 </SectionHeader>
88 {iCloudOpen && (
89 <InsetCard data-spotlight="folder-counts">
90 <InsetRow first separatorInset={58}>
91 <FolderRow folderId="all" icon={<FolderGlyph />} name="All iCloud" count={counts.all} />
92 </InsetRow>
93 {iCloudFolders.map((folder) => (
94 <InsetRow key={folder.id} separatorInset={58}>
95 {editing && canRenameFolder(folder) ? (
96 <RenameRow
97 folder={folder}
98 count={counts[folder.id]}
99 onRename={() => setRenaming(folder)}
100 />
101 ) : (
102 <FolderRow
103 folderId={folder.id}
104 icon={<FolderGlyph />}
105 name={folder.name}
106 count={counts[folder.id]}
107 />
108 )}
109 </InsetRow>
110 ))}
111 <InsetRow separatorInset={58}>
112 <FolderRow
113 folderId="recently-deleted"
114 icon={<Trash className="size-[26px] text-notes-accent" strokeWidth={1.6} />}
115 name="Recently Deleted"
116 count={counts["recently-deleted"]}
117 />
118 </InsetRow>
119 </InsetCard>
120 )}
121
122 <SectionHeader chevron open={false}>
123 Tags
124 </SectionHeader>
125
126 <SectionHeader>Account</SectionHeader>
127 <InsetCard>
128 <InsetRow first separatorInset={58}>
129 <Link to="/settings" className="flex min-h-[60px] items-center gap-3 px-4 py-2">
130 <AccountAvatar name={account?.name ?? ""} className="size-[30px]" />
131 <span className="min-w-0 flex-1 leading-tight">
132 <span className="block truncate text-[17px]">{account?.name}</span>
133 <span className="block truncate text-[14px] text-ios-secondary">
134 {account?.email}
135 </span>
136 </span>
137 <RowChevron />
138 </Link>
139 </InsetRow>
140 <InsetRow separatorInset={58}>
141 <Link to="/analytics" className="flex h-[52px] items-center gap-3 px-4">
142 <span className="grid w-[30px] place-items-center">
143 <ChartColumn className="size-[24px] text-notes-accent" strokeWidth={1.8} />
144 </span>
145 <span className="flex-1 text-[17px]">Analytics</span>
146 <RowChevron />
147 </Link>
148 </InsetRow>
149 </InsetCard>
150
151 <RenameFolderDialog folder={renaming} onOpenChange={(open) => !open && setRenaming(null)} />
152 </IosScreen>
153 );
154}
155
156/** In Edit mode, tapping a folder renames it instead of opening it. */
157function RenameRow({
158 folder,
159 count,
160 onRename,
161}: {
162 folder: FolderRecord;
163 count: number | undefined;
164 onRename: () => void;
165}) {
166 return (
167 <button
168 type="button"
169 onClick={onRename}
170 aria-label={`Rename ${folder.name}`}
171 className="flex h-[52px] w-full items-center gap-3 px-4 text-left active:bg-black/5 dark:active:bg-white/5"
172 >
173 <span className="grid w-[30px] place-items-center">
174 <FolderGlyph />
175 </span>
176 <span className="min-w-0 flex-1 truncate text-[17px]">{folder.name}</span>
177 <span className="text-[17px] text-ios-secondary tabular-nums">{count ?? 0}</span>
178 <Pencil className="size-[18px] shrink-0 text-notes-accent" strokeWidth={2.2} />
179 </button>
180 );
181}
182
183function FolderRow({
184 folderId,
185 icon,
186 name,
187 count,
188}: {
189 folderId: string;
190 icon: ReactNode;
191 name: string;
192 count: number | undefined;
193}) {
194 return (
195 <Link
196 to="/folders/$folderId"
197 params={{ folderId }}
198 onClick={() =>
199 reportAction({ type: "folder.opened", folderId, smart: isSmartFolderId(folderId) })
200 }
201 className="flex h-[52px] items-center gap-3 px-4 active:bg-black/5 dark:active:bg-white/5"
202 >
203 <span className="grid w-[30px] place-items-center">{icon}</span>
204 <span className="min-w-0 flex-1 truncate text-[17px]">{name}</span>
205 <span className="text-[17px] text-ios-secondary tabular-nums">{count ?? 0}</span>
206 <RowChevron />
207 </Link>
208 );
209}
210
211function FolderGlyph() {
212 return <Folder className="size-[26px] text-notes-accent" strokeWidth={1.6} />;
213}