diff --git a/src/modules/notes/components/note-editor.tsx b/src/modules/notes/components/note-editor.tsx index 6b2e5f6..476567d 100644 --- a/src/modules/notes/components/note-editor.tsx +++ b/src/modules/notes/components/note-editor.tsx @@ -2,10 +2,9 @@ import dynamic from "next/dynamic"; import { useRouter } from "next/navigation"; -import { Pin, PinOff, Save, Trash2 } from "lucide-react"; +import { Bell, Pencil, Pin, PinOff, Save, Trash2, X } from "lucide-react"; import { useState, useTransition } from "react"; import { EntityComments } from "@/components/comments/entity-comments"; -import { RichTextContent } from "@/components/rich-text"; import { DetailBackLink } from "@/components/detail-back-link"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; @@ -13,6 +12,7 @@ import { Label } from "@/components/ui/label"; import { ShareButton } from "@/components/share-button"; import type { NoteDto } from "../server/queries"; import { createNote, deleteNote, setNotePinned, updateNote } from "../server/actions"; +import { NoteRichTextBody } from "./note-rich-text-body"; const RichTextEditor = dynamic( () => import("@/components/rich-text/rich-text-editor").then((mod) => mod.RichTextEditor), @@ -29,6 +29,7 @@ const RichTextEditor = dynamic( export function NoteEditor({ note, currentUserId }: { note?: NoteDto; currentUserId?: string }) { const router = useRouter(); const [currentNote, setCurrentNote] = useState(note); + const [editing, setEditing] = useState(!note); const [title, setTitle] = useState(note?.title ?? ""); const [body, setBody] = useState(note?.body ?? ""); const [remindAt, setRemindAt] = useState(toLocalDateTimeValue(note?.remindAt ?? null)); @@ -36,6 +37,25 @@ export function NoteEditor({ note, currentUserId }: { note?: NoteDto; currentUse const pinned = currentNote?.pinned ?? false; + function beginEdit() { + if (!currentNote) return; + setTitle(currentNote.title); + setBody(currentNote.body); + setRemindAt(toLocalDateTimeValue(currentNote.remindAt)); + setEditing(true); + } + + function cancelEdit() { + if (!currentNote) { + router.push("/notes"); + return; + } + setTitle(currentNote.title); + setBody(currentNote.body); + setRemindAt(toLocalDateTimeValue(currentNote.remindAt)); + setEditing(false); + } + function saveNote() { startTransition(async () => { if (currentNote) { @@ -46,6 +66,7 @@ export function NoteEditor({ note, currentUserId }: { note?: NoteDto; currentUse remindAt: remindAt ? new Date(remindAt) : null, }); setCurrentNote(updated); + setEditing(false); return; } @@ -73,38 +94,87 @@ export function NoteEditor({ note, currentUserId }: { note?: NoteDto; currentUse }); } + const displayTitle = currentNote?.title || title || "New note"; + const updatedLabel = currentNote + ? new Date(currentNote.updatedAt).toLocaleDateString(undefined, { + year: "numeric", + month: "long", + day: "numeric", + }) + : null; + const reminderLabel = currentNote?.remindAt + ? new Date(currentNote.remindAt).toLocaleString(undefined, { + year: "numeric", + month: "short", + day: "numeric", + hour: "numeric", + minute: "2-digit", + }) + : null; + return ( -
+
-
- {pinned && } -

- {currentNote ? currentNote.title : "New note"} -

+
+
+ {pinned ? : null} +

+ {displayTitle} +

+
+ {!editing && currentNote ? ( +

+ {pinned ? Pinned : null} + {pinned && updatedLabel ? · : null} + {updatedLabel ? Updated {updatedLabel} : null} + {reminderLabel ? ( + <> + · + + + {reminderLabel} + + + ) : null} +

+ ) : null}
{currentNote ? ( ) : null} {currentNote ? : null} {currentNote ? ( ) : null} - + {editing ? ( + <> + + + + ) : ( + + )}
-
+ {editing ? (
- - -
+ {currentNote.body ? ( + + ) : ( +

No body text.

+ )} + + ) : null} {currentNote && currentUserId ? (