hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBc35a83aBurak Boduroğlu4 months ago440 commits
| 1 | import { createSignal } from "solid-js"; |
| 2 | import { formatApiError } from "@/api/client"; |
| 3 | import type { Note } from "@/api/client"; |
| 4 | import { NoteForm } from "@/components/notes/note-form"; |
| 5 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 6 | import { IconEdit, IconTrash } from "@/components/ui/icons"; |
| 7 | import { SidePanel } from "@/components/ui/side-panel"; |
| 8 | import { TableRowActions } from "@/components/ui/table-row-actions"; |
| 9 | import { useT } from "@/stores/preferences-context"; |
| 10 | |
| 11 | export function NoteCard(props: { |
| 12 | note: Note; |
| 13 | onOpen: (note: Note) => void; |
| 14 | onUpdate: (id: string, values: { title: string; content: string }) => Promise<void>; |
| 15 | onDelete: (id: string) => Promise<void>; |
| 16 | }) { |
| 17 | const t = useT(); |
| 18 | const [editing, setEditing] = createSignal(false); |
| 19 | const [error, setError] = createSignal(""); |
| 20 | const [deleteOpen, setDeleteOpen] = createSignal(false); |
| 21 | |
| 22 | return ( |
| 23 | <> |
| 24 | <article |
| 25 | role="button" |
| 26 | tabindex="0" |
| 27 | class="group flex h-full min-h-72 cursor-pointer flex-col overflow-hidden rounded-lg border border-amber-500/40 bg-card shadow-sm transition-shadow hover:border-amber-400/60 hover:shadow-md focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring dark:border-amber-500/30 dark:hover:border-amber-400/60" |
| 28 | onClick={() => props.onOpen(props.note)} |
| 29 | onKeyDown={(event) => { |
| 30 | if (event.key === "Enter" || event.key === " ") { |
| 31 | event.preventDefault(); |
| 32 | props.onOpen(props.note); |
| 33 | } |
| 34 | }} |
| 35 | > |
| 36 | <div class="flex items-start justify-between gap-3 border-b border-amber-500/30 bg-muted/40 px-4 py-3 dark:border-amber-500/30 dark:bg-muted/30"> |
| 37 | <h3 class="line-clamp-2 min-w-0 text-base font-semibold leading-snug">{props.note.title}</h3> |
| 38 | <div class="shrink-0" onClick={(event) => event.stopPropagation()}> |
| 39 | <TableRowActions |
| 40 | label={t("common.actions")} |
| 41 | actions={[ |
| 42 | { |
| 43 | label: t("common.edit"), |
| 44 | icon: <IconEdit class="h-4 w-4" />, |
| 45 | onSelect: () => setEditing(true), |
| 46 | }, |
| 47 | { |
| 48 | label: t("common.delete"), |
| 49 | icon: <IconTrash class="h-4 w-4" />, |
| 50 | destructive: true, |
| 51 | onSelect: () => setDeleteOpen(true), |
| 52 | }, |
| 53 | ]} |
| 54 | /> |
| 55 | </div> |
| 56 | </div> |
| 57 | <div class="flex flex-1 flex-col gap-4 bg-[linear-gradient(90deg,rgba(245,158,11,0.12)_0,rgba(245,158,11,0.12)_2.25rem,transparent_2.25rem),repeating-linear-gradient(0deg,transparent_0,transparent_2.05rem,rgba(120,113,108,0.14)_2.1rem)] px-4 py-4 pl-12 dark:bg-[linear-gradient(90deg,rgba(245,158,11,0.1)_0,rgba(245,158,11,0.1)_2.25rem,transparent_2.25rem),repeating-linear-gradient(0deg,transparent_0,transparent_2.05rem,rgba(214,211,209,0.1)_2.1rem)]"> |
| 58 | <p class="line-clamp-6 whitespace-pre-wrap text-[13px] leading-8 text-muted-foreground group-hover:text-foreground"> |
| 59 | {props.note.content || t("notes.noContent")} |
| 60 | </p> |
| 61 | {error() && <p class="text-sm text-destructive">{error()}</p>} |
| 62 | </div> |
| 63 | </article> |
| 64 | |
| 65 | <SidePanel open={editing()} onOpenChange={setEditing} title={t("common.edit")} description={props.note.title}> |
| 66 | <NoteForm |
| 67 | initial={props.note} |
| 68 | submitLabel={t("common.update")} |
| 69 | onCancel={() => setEditing(false)} |
| 70 | onSubmit={async (values) => { |
| 71 | await props.onUpdate(props.note.id, values); |
| 72 | setEditing(false); |
| 73 | }} |
| 74 | /> |
| 75 | </SidePanel> |
| 76 | |
| 77 | <ConfirmDialog |
| 78 | open={deleteOpen()} |
| 79 | onOpenChange={setDeleteOpen} |
| 80 | title={t("confirm.deleteTitle")} |
| 81 | variant="destructive" |
| 82 | summary={t("confirm.deleteNote", { title: props.note.title })} |
| 83 | onConfirm={async () => { |
| 84 | setError(""); |
| 85 | try { |
| 86 | await props.onDelete(props.note.id); |
| 87 | } catch (err) { |
| 88 | setError(formatApiError(err)); |
| 89 | throw err; |
| 90 | } |
| 91 | }} |
| 92 | /> |
| 93 | </> |
| 94 | ); |
| 95 | } |