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