hezarfen_frontend
Clone
https://git.tahinli.com/Hezarfen/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import { For, Show, createSignal } from "solid-js"; |
| 2 | import type { Note } from "@/api/client"; |
| 3 | import type { NoteFileSource } from "@/lib/note-source"; |
| 4 | import { NoteCard } from "@/components/notes/note-card"; |
| 5 | import { NoteReaderPanel } from "@/components/notes/note-reader-panel"; |
| 6 | import { EmptyState } from "@/components/ui/empty-state"; |
| 7 | |
| 8 | export function NoteList(props: { |
| 9 | notes: Note[]; |
| 10 | /** Which note family these belong to — decides the file routes behind them. */ |
| 11 | source: NoteFileSource; |
| 12 | /** Hides edit/delete and the file controls when false. Defaults to true. */ |
| 13 | canManage?: boolean; |
| 14 | emptyTitle: string; |
| 15 | emptyDescription?: string; |
| 16 | /** Opens a note somewhere else (its own page) instead of the reader panel; also used for edit. */ |
| 17 | onOpen?: (note: Note) => void; |
| 18 | onUpdate: (id: string, values: { title: string; content: string }) => Promise<void>; |
| 19 | onDelete: (id: string) => Promise<void>; |
| 20 | }) { |
| 21 | const [readingNote, setReadingNote] = createSignal<Note | null>(null); |
| 22 | |
| 23 | return ( |
| 24 | <> |
| 25 | <Show |
| 26 | when={props.notes.length > 0} |
| 27 | fallback={ |
| 28 | <EmptyState |
| 29 | kind="notes" |
| 30 | title={props.emptyTitle} |
| 31 | description={props.emptyDescription} |
| 32 | /> |
| 33 | } |
| 34 | > |
| 35 | <ul class="grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4"> |
| 36 | <For each={props.notes}> |
| 37 | {(note) => ( |
| 38 | <li class="animate-fade-up"> |
| 39 | <NoteCard |
| 40 | note={note} |
| 41 | canManage={props.canManage} |
| 42 | onOpen={(item) => (props.onOpen ? props.onOpen(item) : setReadingNote(item))} |
| 43 | onEdit={props.onOpen} |
| 44 | onUpdate={props.onUpdate} |
| 45 | onDelete={props.onDelete} |
| 46 | /> |
| 47 | </li> |
| 48 | )} |
| 49 | </For> |
| 50 | </ul> |
| 51 | </Show> |
| 52 | |
| 53 | <NoteReaderPanel |
| 54 | note={readingNote()} |
| 55 | source={props.source} |
| 56 | canManage={props.canManage} |
| 57 | open={readingNote() != null} |
| 58 | onOpenChange={(open) => { |
| 59 | if (!open) setReadingNote(null); |
| 60 | }} |
| 61 | /> |
| 62 | </> |
| 63 | ); |
| 64 | } |