import { Show, createSignal } from "solid-js"; import { formatApiError } from "@/api/client"; import type { Note } from "@/api/client"; import { NoteForm } from "@/components/notes/note-form"; import { ConfirmDialog } from "@/components/ui/confirm-dialog"; import { IconChevronRight, IconEdit, IconTrash } from "@/components/ui/icons"; import { SidePanel } from "@/components/ui/side-panel"; import { TableRowActions } from "@/components/ui/table-row-actions"; import { cn } from "@/lib/cn"; import { richTextExcerpt, toRichTextHtml } from "@/lib/rich-text"; import { useT } from "@/stores/preferences-context"; export function NoteCard(props: { note: Note; /** Hides the edit/delete menu when false. Defaults to true. */ canManage?: boolean; onOpen: (note: Note) => void; /** Edits somewhere else (the full-page editor) instead of the side panel. */ onEdit?: (note: Note) => void; onUpdate: (id: string, values: { title: string; content: string }) => Promise; onDelete: (id: string) => Promise; }) { const t = useT(); const [editing, setEditing] = createSignal(false); const [error, setError] = createSignal(""); const [deleteOpen, setDeleteOpen] = createSignal(false); const canManage = () => props.canManage !== false; const excerpt = () => richTextExcerpt(toRichTextHtml(props.note.content), 320); return ( <> {/* The title is the card's one open control, stretched over the whole card; the actions menu sits above it. A role="button" card wrapping the menu nested one button in another, and Enter on the menu trigger bubbled up and opened the note. */}

, onSelect: () => (props.onEdit ? props.onEdit(props.note) : setEditing(true)), }, { label: t("common.delete"), icon: , destructive: true, onSelect: () => setDeleteOpen(true), }, ]} />
{/* Plain-text excerpt: the card never renders stored HTML. */}

{excerpt() || t("notes.noContent")}

{error() &&

{error()}

}
setEditing(false)} onSubmit={async (values) => { await props.onUpdate(props.note.id, values); setEditing(false); }} /> { setError(""); try { await props.onDelete(props.note.id); } catch (err) { setError(formatApiError(err)); throw err; } }} /> ); }