Open History to see the last commit
1import { Link } from "@tanstack/react-router";
2import { Ellipsis, Folder, Share } from "lucide-react";
3import { useState } from "react";
4
5import { ContextMenu, ContextMenuContent, ContextMenuTrigger } from "@/components/ui/context-menu";
6import { useFolderView, useNoteList } from "@/db/queries";
7import type { NoteListItem } from "@/db/queries";
8import { reportAction } from "@/lib/app-actions";
9import { formatListDate } from "@/lib/notes/dates";
10import { noteDisplayTitle, noteSnippet } from "@/lib/notes/note-body";
11import { noteListSections } from "@/lib/notes/note-list";
12
13import { NoteActionItems } from "../note-actions";
14import { useComposeNote } from "../use-compose-note";
15
16import {
17 BackLink,
18 GlassPill,
19 GlassPillButton,
20 InsetCard,
21 InsetRow,
22 IosScreen,
23 LargeTitle,
24 SearchAndCompose,
25 SectionHeader,
26} from "./ui";
27
28export function IosNoteListScreen({ folderId }: { folderId: string }) {
29 const { view } = useFolderView(folderId);
30 const { notes, listOptions } = useNoteList(folderId);
31 const [pinnedOpen, setPinnedOpen] = useState(true);
32 const composeNote = useComposeNote();
33
34 const now = new Date();
35 const { pinned, groups } = noteListSections(notes, now, listOptions);
36 const showFolder = view?.showsFolderName ?? false;
37
38 return (
39 <IosScreen
40 leading={<BackLink to="/" aria-label="Folders" />}
41 trailing={
42 <GlassPill>
43 <GlassPillButton aria-label="Share">
44 <Share />
45 </GlassPillButton>
46 <GlassPillButton aria-label="More">
47 <Ellipsis />
48 </GlassPillButton>
49 </GlassPill>
50 }
51 bottom={<SearchAndCompose onCompose={composeNote} />}
52 >
53 <LargeTitle
54 title={view?.name ?? "Notes"}
55 subtitle={`${notes.length} ${notes.length === 1 ? "Note" : "Notes"}`}
56 />
57
58 {notes.length === 0 && (
59 <p className="pt-16 text-center text-[17px] text-ios-secondary">No Notes</p>
60 )}
61
62 <div data-spotlight="note-list">
63 {pinned.length > 0 && (
64 <>
65 <SectionHeader
66 chevron
67 open={pinnedOpen}
68 onToggle={() => setPinnedOpen((open) => !open)}
69 >
70 Pinned
71 </SectionHeader>
72 {pinnedOpen && (
73 <NoteCard notes={pinned} folderId={folderId} showFolder={showFolder} now={now} />
74 )}
75 </>
76 )}
77
78 {groups.map((group) => (
79 <div key={group.label}>
80 {group.label ? <SectionHeader>{group.label}</SectionHeader> : <div className="h-5" />}
81 <NoteCard notes={group.items} folderId={folderId} showFolder={showFolder} now={now} />
82 </div>
83 ))}
84 </div>
85 </IosScreen>
86 );
87}
88
89function NoteCard({
90 notes,
91 folderId,
92 showFolder,
93 now,
94}: {
95 notes: NoteListItem[];
96 folderId: string;
97 showFolder: boolean;
98 now: Date;
99}) {
100 return (
101 <InsetCard>
102 {notes.map((note, index) => (
103 <InsetRow key={note.id} first={index === 0} separatorInset={26}>
104 {/* Long-press for the note's actions, like in Notes. */}
105 <ContextMenu>
106 <ContextMenuTrigger asChild>
107 <Link
108 to="/folders/$folderId/notes/$noteId"
109 params={{ folderId, noteId: note.id }}
110 onClick={() => reportAction({ type: "note.opened", noteId: note.id })}
111 className="block px-[26px] py-[11px] select-none [-webkit-touch-callout:none] active:bg-black/5 data-[state=open]:bg-black/5 dark:active:bg-white/5 dark:data-[state=open]:bg-white/5"
112 >
113 <NoteRowText note={note} showFolder={showFolder} now={now} />
114 </Link>
115 </ContextMenuTrigger>
116 <ContextMenuContent className="min-w-48">
117 <NoteActionItems note={note} menu="context" />
118 </ContextMenuContent>
119 </ContextMenu>
120 </InsetRow>
121 ))}
122 </InsetCard>
123 );
124}
125
126function NoteRowText({
127 note,
128 showFolder,
129 now,
130}: {
131 note: NoteListItem;
132 showFolder: boolean;
133 now: Date;
134}) {
135 return (
136 <>
137 <p className="truncate text-[17px] leading-snug font-semibold">
138 {noteDisplayTitle(note.title)}
139 </p>
140 <p className="flex gap-2 text-[15px] leading-snug text-ios-secondary">
141 <span className="shrink-0">{formatListDate(new Date(note.updatedAt), now)}</span>
142 <span className="truncate">{noteSnippet(note.body)}</span>
143 </p>
144 {showFolder && note.folderName && (
145 <p className="mt-0.5 flex items-center gap-1.5 text-[15px] leading-snug text-ios-secondary">
146 <Folder className="size-4 shrink-0" />
147 <span className="truncate">{note.folderName}</span>
148 </p>
149 )}
150 </>
151 );
152}