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 { useFolders, useFolderView, useNotesInFolder } from "@/data/notes-data";
6import type { Note } from "@/fixtures";
7import { formatListDate } from "@/lib/notes/dates";
8import { noteSnippet } from "@/lib/notes/note-body";
9import { noteListSections } from "@/lib/notes/note-list";
10
11import {
12 BackLink,
13 GlassPill,
14 GlassPillButton,
15 InsetCard,
16 InsetRow,
17 IosScreen,
18 LargeTitle,
19 SearchAndCompose,
20 SectionHeader,
21} from "./ui";
22
23export function IosNoteListScreen({ folderId }: { folderId: string }) {
24 const view = useFolderView(folderId);
25 const notes = useNotesInFolder(folderId);
26 const [pinnedOpen, setPinnedOpen] = useState(true);
27
28 const now = new Date();
29 const { pinned, groups } = noteListSections(notes, now);
30 const showFolder = view?.showsFolderName ?? false;
31
32 return (
33 <IosScreen
34 leading={<BackLink to="/" aria-label="Folders" />}
35 trailing={
36 <GlassPill>
37 <GlassPillButton aria-label="Share">
38 <Share />
39 </GlassPillButton>
40 <GlassPillButton aria-label="More">
41 <Ellipsis />
42 </GlassPillButton>
43 </GlassPill>
44 }
45 bottom={<SearchAndCompose />}
46 >
47 <LargeTitle
48 title={view?.name ?? "Notes"}
49 subtitle={`${notes.length} ${notes.length === 1 ? "Note" : "Notes"}`}
50 />
51
52 {notes.length === 0 && (
53 <p className="pt-16 text-center text-[17px] text-ios-secondary">No Notes</p>
54 )}
55
56 {pinned.length > 0 && (
57 <>
58 <SectionHeader chevron open={pinnedOpen} onToggle={() => setPinnedOpen((open) => !open)}>
59 Pinned
60 </SectionHeader>
61 {pinnedOpen && (
62 <NoteCard notes={pinned} folderId={folderId} showFolder={showFolder} now={now} />
63 )}
64 </>
65 )}
66
67 {groups.map((group) => (
68 <div key={group.label}>
69 <SectionHeader>{group.label}</SectionHeader>
70 <NoteCard notes={group.items} folderId={folderId} showFolder={showFolder} now={now} />
71 </div>
72 ))}
73 </IosScreen>
74 );
75}
76
77function NoteCard({
78 notes,
79 folderId,
80 showFolder,
81 now,
82}: {
83 notes: Note[];
84 folderId: string;
85 showFolder: boolean;
86 now: Date;
87}) {
88 const folders = useFolders();
89 return (
90 <InsetCard>
91 {notes.map((note, index) => {
92 const folderName = folders.find((folder) => folder.id === note.folderId)?.name;
93 return (
94 <InsetRow key={note.id} first={index === 0} separatorInset={26}>
95 <Link
96 to="/folders/$folderId/notes/$noteId"
97 params={{ folderId, noteId: note.id }}
98 className="block px-[26px] py-[11px] active:bg-black/5 dark:active:bg-white/5"
99 >
100 <p className="truncate text-[17px] leading-snug font-semibold">{note.title}</p>
101 <p className="flex gap-2 text-[15px] leading-snug text-ios-secondary">
102 <span className="shrink-0">{formatListDate(new Date(note.updatedAt), now)}</span>
103 <span className="truncate">{noteSnippet(note.body)}</span>
104 </p>
105 {showFolder && folderName && (
106 <p className="mt-0.5 flex items-center gap-1.5 text-[15px] leading-snug text-ios-secondary">
107 <Folder className="size-4 shrink-0" />
108 <span className="truncate">{folderName}</span>
109 </p>
110 )}
111 </Link>
112 </InsetRow>
113 );
114 })}
115 </InsetCard>
116 );
117}