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