Skip to content
Source
Sign inSign up
fuko/trytanstackdb-v2
Open History to see the last commit

note-list.ts

26 lines804 Bytes

1import type { Note } from "@/fixtures";
2​
3import { groupByDate } from "./dates";
4import type { DateGroup } from "./dates";
5​
6export interface NoteListSections {
7 pinned: Note[];
8 groups: DateGroup<Note>[];
9}
10​
11/** Splits a folder's notes (newest first) into the Pinned section and date groups. */
12export function noteListSections(notes: Note[], now: Date): NoteListSections {
13 return {
14 pinned: notes.filter((note) => note.pinned),
15 groups: groupByDate(
16 notes.filter((note) => !note.pinned),
17 (note) => new Date(note.updatedAt),
18 now,
19 ),
20 };
22​
23/** Notes in the order they appear on screen: pinned first, then by date. */
24export function notesInDisplayOrder(notes: Note[]): Note[] {
25 return [...notes.filter((note) => note.pinned), ...notes.filter((note) => !note.pinned)];