forge
Explore
Log in

Don't you dare go Hollow

✨ full-page rich text notes editor

Browse files at this commit

622395268ed2ca8c8b928f1d194afef3b00d7654Burak BoduroğluParent: 78600ff
  • feat
    • ✨ full-page rich text notes editor
Show full message
feat: ✨ full-page rich text notes editor
- personal notes open at /notes/new and /notes/$id as a document: large
  title, sticky formatting bar (headings, marks, link, lists, quote, code),
  Cmd+S save, Cmd+K link, and an unsaved-changes guard on leave
- attachments sit beside the editor on wide screens
- note cards show a clean plain-text excerpt; the reader panel and course
  note form use the same editor and prose styles
- ui-conventions documents the editor and the sanitize rule
.claude/skills/ui-conventions/SKILL.mdmodified+2 -0
@@ -67,4 +67,6 @@ Active project reference docs (read the relevant one before changing that area):
6767 ## Features
6868
6969 - **Note Import Assistant:** Raw PDF/TXT/MD converted to structured Markdown via `src/lib/note-importer.ts`. Noise (page numbers, headers/footers, watermarks) removed, PDF mid-sentence line wraps re-joined, headings (`##`) and bullet lists formatted, OCR-unreadable artifacts flagged with `⚠️ Some content may be unreadable due to OCR/extraction issues`. Never invent content or add fluff preamble. Lives in a dedicated `SidePanel` triggered from the Notes page header, right of the "Yeni Not" button.
70+- **Notes editor:** Personal notes open as full pages — `/notes/new` and `/notes/$id` (`NoteDocument`) — not side panels. Bodies are HTML written by `NoteRichEditor` (contentEditable, sticky toolbar, ⌘S save, ⌘K link, unsaved-changes blocker); course notes use the same editor inside `NoteForm`. Stored Markdown-ish bodies (imports, older notes) load through `toRichTextHtml`.
71+- **Rendering stored HTML:** anything a user wrote that reaches `innerHTML` (notes, messages, homework submissions) goes through `sanitizeRichText` / `toRichTextHtml` from `src/lib/rich-text.ts`. Card excerpts use `richTextExcerpt` (plain text), never `innerHTML`.
7072 - **Drawing Canvas (`DrawCanvas`):** Freehand drawings saved as `.hzdraw.png` with embedded scene JSON metadata. Live drawing effects must guard `initialScene` against re-initializing during active strokes.
src/components/layout/command-palette.tsxmodified+1 -1
@@ -153,7 +153,7 @@ export function CommandPalette(props: CommandPaletteProps) {
153153 keywords: "note not ekle ders notu kaydet",
154154 icon: IconNote,
155155 shortcut: `${mod}N`,
156- onSelect: () => void navigate({ to: "/notes", search: { action: "new" } as any }),
156+ onSelect: () => void navigate({ to: "/notes/new" }),
157157 });
158158
159159 list.push({
src/components/notes/note-card.tsxmodified+20 -15
@@ -3,9 +3,11 @@ import { formatApiError } from "@/api/client";
33 import type { Note } from "@/api/client";
44 import { NoteForm } from "@/components/notes/note-form";
55 import { ConfirmDialog } from "@/components/ui/confirm-dialog";
6-import { IconEdit, IconTrash } from "@/components/ui/icons";
6+import { IconChevronRight, IconEdit, IconTrash } from "@/components/ui/icons";
77 import { SidePanel } from "@/components/ui/side-panel";
88 import { TableRowActions } from "@/components/ui/table-row-actions";
9+import { cn } from "@/lib/cn";
10+import { richTextExcerpt, toRichTextHtml } from "@/lib/rich-text";
911 import { useT } from "@/stores/preferences-context";
1012
1113 export function NoteCard(props: {
@@ -13,6 +15,8 @@ export function NoteCard(props: {
1315 /** Hides the edit/delete menu when false. Defaults to true. */
1416 canManage?: boolean;
1517 onOpen: (note: Note) => void;
18+ /** Edits somewhere else (the full-page editor) instead of the side panel. */
19+ onEdit?: (note: Note) => void;
1620 onUpdate: (id: string, values: { title: string; content: string }) => Promise<void>;
1721 onDelete: (id: string) => Promise<void>;
1822 }) {
@@ -21,13 +25,14 @@ export function NoteCard(props: {
2125 const [error, setError] = createSignal("");
2226 const [deleteOpen, setDeleteOpen] = createSignal(false);
2327 const canManage = () => props.canManage !== false;
28+ const excerpt = () => richTextExcerpt(toRichTextHtml(props.note.content), 320);
2429
2530 return (
2631 <>
2732 <article
2833 role="button"
2934 tabindex="0"
30- 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"
35+ class="group flex h-full min-h-44 cursor-pointer flex-col rounded-xl border border-border bg-card p-4 shadow-xs transition-[border-color,box-shadow] hover:border-primary/40 hover:shadow-md focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring"
3136 onClick={() => props.onOpen(props.note)}
3237 onKeyDown={(event) => {
3338 if (event.key === "Enter" || event.key === " ") {
@@ -36,17 +41,17 @@ export function NoteCard(props: {
3641 }
3742 }}
3843 >
39- <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">
40- <h3 class="line-clamp-2 min-w-0 text-base font-semibold leading-snug">{props.note.title}</h3>
44+ <div class="flex items-start justify-between gap-3">
45+ <h3 class="line-clamp-2 min-w-0 text-[15px] font-semibold leading-snug text-text-strong">{props.note.title}</h3>
4146 <Show when={canManage()}>
42- <div class="shrink-0" onClick={(event) => event.stopPropagation()}>
47+ <div class="-mr-1.5 -mt-1 shrink-0" onClick={(event) => event.stopPropagation()}>
4348 <TableRowActions
4449 label={t("common.actions")}
4550 actions={[
4651 {
4752 label: t("common.edit"),
4853 icon: <IconEdit class="h-4 w-4" />,
49- onSelect: () => setEditing(true),
54+ onSelect: () => (props.onEdit ? props.onEdit(props.note) : setEditing(true)),
5055 },
5156 {
5257 label: t("common.delete"),
@@ -59,15 +64,15 @@ export function NoteCard(props: {
5964 </div>
6065 </Show>
6166 </div>
62- <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)]">
63- <Show
64- when={props.note.content?.trim()}
65- fallback={<p class="text-[13px] leading-8 text-muted-foreground">{t("notes.noContent")}</p>}
66- >
67- <div class="line-clamp-6 whitespace-pre-wrap text-[13px] leading-8 text-muted-foreground group-hover:text-foreground [&_ol]:ml-5 [&_ol]:list-decimal [&_ul]:ml-5 [&_ul]:list-disc" innerHTML={props.note.content} />
68- </Show>
69- {error() && <p class="text-sm text-destructive">{error()}</p>}
70- </div>
67+ {/* Plain-text excerpt: the card never renders stored HTML. */}
68+ <p class={cn("mt-2 line-clamp-5 flex-1 text-[13px] leading-6", excerpt() ? "text-muted-foreground" : "italic text-muted-foreground/70")}>
69+ {excerpt() || t("notes.noContent")}
70+ </p>
71+ <span class="mt-3 inline-flex items-center gap-1 text-xs font-medium text-primary opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100">
72+ {t("notes.open")}
73+ <IconChevronRight class="h-3.5 w-3.5" />
74+ </span>
75+ {error() && <p class="mt-2 text-sm text-destructive">{error()}</p>}
7176 </article>
7277
7378 <SidePanel open={editing()} onOpenChange={setEditing} title={t("common.edit")} description={props.note.title}>
src/components/notes/note-document.tsxadded+179 -0
@@ -0,0 +1,179 @@
1+import { Link, useBlocker, useNavigate } from "@tanstack/solid-router";
2+import { Show, createSignal, onCleanup, onMount } from "solid-js";
3+import { formatApiError, type Note } from "@/api/client";
4+import { deleteNoteById, patchNoteById, postNote } from "@/api/notes";
5+import { NoteFilesPanel } from "@/components/notes/note-files-panel";
6+import { NoteRichEditor } from "@/components/notes/note-rich-editor";
7+import { Alert } from "@/components/ui/alert";
8+import { Button } from "@/components/ui/button";
9+import { ConfirmDialog } from "@/components/ui/confirm-dialog";
10+import { IconAlert, IconChevronLeft, IconTrash } from "@/components/ui/icons";
11+import { cn } from "@/lib/cn";
12+import { personalNoteFiles } from "@/lib/note-source";
13+import { useT } from "@/stores/preferences-context";
14+
15+const MAX_TITLE = 200;
16+const MAX_CONTENT = 10_000;
17+const MOD_KEY = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.userAgent) ? "⌘" : "Ctrl";
18+
19+/**
20+ * A personal note as a full-page document: title, editor, attachments. A new
21+ * note (no `note`) becomes a real one on first save and moves to its own URL,
22+ * where attachments open up. Leaving with unsaved edits asks first.
23+ */
24+export function NoteDocument(props: { note?: Note }) {
25+ const t = useT();
26+ const navigate = useNavigate();
27+ const [title, setTitle] = createSignal(props.note?.title ?? "");
28+ const [content, setContent] = createSignal(props.note?.content ?? "");
29+ const [baseline, setBaseline] = createSignal(JSON.stringify([props.note?.title ?? "", props.note?.content ?? ""]));
30+ const [saving, setSaving] = createSignal(false);
31+ const [error, setError] = createSignal("");
32+ const [deleteOpen, setDeleteOpen] = createSignal(false);
33+ const dirty = () => JSON.stringify([title(), content()]) !== baseline();
34+ const isNew = () => !props.note;
35+
36+ let leaving = false;
37+ const blocker = useBlocker({ shouldBlockFn: () => dirty(), enableBeforeUnload: () => dirty(), withResolver: true });
38+
39+ const save = async () => {
40+ if (saving()) return;
41+ const trimmed = title().trim();
42+ if (!trimmed) return setError(t("form.titleRequired"));
43+ if (trimmed.length > MAX_TITLE) return setError(t("form.titleMax"));
44+ if (content().length > MAX_CONTENT) return setError(t("form.contentMax"));
45+ setError("");
46+ setSaving(true);
47+ // What is being saved, captured now: typing that lands while the request
48+ // is out must still count as unsaved afterwards.
49+ const body = content();
50+ try {
51+ if (props.note) {
52+ await patchNoteById(props.note.id, { title: trimmed, content: body });
53+ if (title().trim() === trimmed) setTitle(trimmed);
54+ setBaseline(JSON.stringify([trimmed, body]));
55+ } else {
56+ const created = await postNote({ title: trimmed, content: body || undefined });
57+ // Settle the baseline first so the move to the note's URL is not blocked.
58+ setBaseline(JSON.stringify([title(), content()]));
59+ await navigate({ to: "/notes/$id", params: { id: created.id }, replace: true });
60+ }
61+ } catch (err) {
62+ setError(formatApiError(err));
63+ } finally {
64+ setSaving(false);
65+ }
66+ };
67+
68+ onMount(() => {
69+ const onKey = (event: KeyboardEvent) => {
70+ if (!(event.metaKey || event.ctrlKey) || event.altKey || event.shiftKey || event.key.toLowerCase() !== "s") return;
71+ event.preventDefault();
72+ void save();
73+ };
74+ window.addEventListener("keydown", onKey);
75+ onCleanup(() => window.removeEventListener("keydown", onKey));
76+ });
77+
78+ const status = () => (saving() ? t("notes.saving") : dirty() ? t("notes.unsaved") : isNew() ? "" : t("notes.allSaved"));
79+
80+ return (
81+ <div class="space-y-4">
82+ <div class="flex items-center gap-3">
83+ <Link to="/notes" class="inline-flex h-8 items-center gap-1 rounded-lg px-2 text-sm text-muted-foreground transition-colors hover:bg-muted hover:text-foreground">
84+ <IconChevronLeft class="h-4 w-4" />
85+ {t("notes.backToNotebook")}
86+ </Link>
87+ <span class={cn("ml-auto text-xs", dirty() ? "text-amber-600 dark:text-amber-400" : "text-muted-foreground")} aria-live="polite">
88+ {status()}
89+ </span>
90+ <Show when={props.note}>
91+ <Button type="button" variant="outline" size="sm" class="rounded-lg text-destructive hover:text-destructive" onClick={() => setDeleteOpen(true)}>
92+ <IconTrash class="h-4 w-4" />
93+ {t("common.delete")}
94+ </Button>
95+ </Show>
96+ </div>
97+
98+ <Show when={error()}>
99+ <Alert variant="destructive">{error()}</Alert>
100+ </Show>
101+
102+ <div class="grid gap-6 xl:grid-cols-[minmax(0,1fr)_340px]">
103+ <div class="min-w-0 space-y-3">
104+ <input
105+ class="w-full bg-transparent px-1 text-3xl font-semibold tracking-tight text-text-strong outline-hidden placeholder:text-muted-foreground/50"
106+ placeholder={t("notes.titlePlaceholder")}
107+ aria-label={t("form.title")}
108+ value={title()}
109+ maxlength={MAX_TITLE}
110+ onInput={(event) => setTitle(event.currentTarget.value)}
111+ onKeyDown={(event) => {
112+ if (event.key === "Enter") event.preventDefault();
113+ }}
114+ />
115+ <NoteRichEditor
116+ value={content()}
117+ onChange={setContent}
118+ placeholder={t("notes.bodyPlaceholder")}
119+ toolbarClass="top-[45px]"
120+ actions={
121+ <>
122+ <span class="hidden text-xs text-muted-foreground md:inline">{t("notes.saveShortcut", { key: MOD_KEY })}</span>
123+ <Button type="button" size="sm" class="min-w-[6.5rem] rounded-lg" disabled={saving() || (!dirty() && !isNew())} onClick={() => void save()}>
124+ {saving() ? t("notes.saving") : t("common.save")}
125+ </Button>
126+ </>
127+ }
128+ />
129+ </div>
130+
131+ <aside class="min-w-0 space-y-4 xl:sticky xl:top-[61px] xl:self-start">
132+ <Show
133+ when={props.note}
134+ fallback={
135+ <section class="rounded-xl border border-dashed border-border bg-card/60 p-4">
136+ <h3 class="text-sm font-semibold">{t("notes.files")}</h3>
137+ <p class="mt-1 text-sm text-muted-foreground">{t("notes.filesAfterSave")}</p>
138+ </section>
139+ }
140+ >
141+ {(note) => <NoteFilesPanel noteId={note().id} source={personalNoteFiles} active />}
142+ </Show>
143+ </aside>
144+ </div>
145+
146+ <ConfirmDialog
147+ open={deleteOpen()}
148+ onOpenChange={setDeleteOpen}
149+ title={t("confirm.deleteTitle")}
150+ variant="destructive"
151+ summary={t("confirm.deleteNote", { title: props.note?.title ?? "" })}
152+ onConfirm={async () => {
153+ if (!props.note) return;
154+ await deleteNoteById(props.note.id);
155+ setBaseline(JSON.stringify([title(), content()]));
156+ await navigate({ to: "/notes" });
157+ }}
158+ />
159+
160+ <ConfirmDialog
161+ open={blocker().status === "blocked"}
162+ onOpenChange={(open) => {
163+ // The dialog also closes itself after "Leave"; only a dismissal resets.
164+ if (!open && !leaving && blocker().status === "blocked") blocker().reset?.();
165+ }}
166+ title={t("notes.leaveTitle")}
167+ description={t("notes.leaveHint")}
168+ summary={title().trim() || t("notes.titlePlaceholder")}
169+ variant="destructive"
170+ icon={<IconAlert class="h-4 w-4" />}
171+ confirmLabel={t("notes.leaveConfirm")}
172+ onConfirm={() => {
173+ leaving = true;
174+ blocker().proceed?.();
175+ }}
176+ />
177+ </div>
178+ );
179+}
src/components/notes/note-form.tsxmodified+10 -32
@@ -3,6 +3,7 @@ import { createResource } from "@/lib/create-resource";
33 import { formatApiError } from "@/api/client";
44 import { getSettings } from "@/api/settings";
55 import type { Note } from "@/api/client";
6+import { NoteRichEditor } from "@/components/notes/note-rich-editor";
67 import { Button } from "@/components/ui/button";
78 import { ConfirmDialog } from "@/components/ui/confirm-dialog";
89 import { FormDialog } from "@/components/ui/form-dialog";
@@ -10,8 +11,6 @@ import { IconEdit, IconPlus, IconTrash } from "@/components/ui/icons";
1011 import { Input } from "@/components/ui/input";
1112 import { Label } from "@/components/ui/label";
1213 import { PageSpinner } from "@/components/ui/page-spinner";
13-import { RichTextEditor } from "@/components/ui/rich-text-editor";
14-import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
1514 import { formatBytes, maxUploadBytes } from "@/lib/upload-limits";
1615 import { useT } from "@/stores/preferences-context";
1716
@@ -38,7 +37,6 @@ export function NoteForm(props: {
3837 const isUpdate = () => !!props.initial?.id;
3938 const [title, setTitle] = createSignal(props.initial?.title ?? "");
4039 const [content, setContent] = createSignal(props.initial?.content ?? "");
41- const [contentView, setContentView] = createSignal<"write" | "preview">("write");
4240 const [files, setFiles] = createSignal<File[]>([]);
4341 const [error, setError] = createSignal("");
4442 const [pending, setPending] = createSignal(false);
@@ -125,35 +123,15 @@ export function NoteForm(props: {
125123 onInput={(e) => setTitle(e.currentTarget.value)}
126124 />
127125 </div>
128- <div class="space-y-1.5 rounded-xl border border-border/80 bg-card p-4 shadow-xs">
129- <div class="flex flex-wrap items-center justify-between gap-2">
130- <Label for="note-content">{t("form.content")}</Label>
131- <Tabs value={contentView()} onChange={(value) => setContentView(value as "write" | "preview")}>
132- <TabsList class="w-auto">
133- <TabsTrigger value="write" class="h-8 px-2.5 text-xs">{t("notes.write")}</TabsTrigger>
134- <TabsTrigger value="preview" class="h-8 px-2.5 text-xs">{t("notes.preview")}</TabsTrigger>
135- </TabsList>
136- <TabsContent value="write" class="hidden" />
137- <TabsContent value="preview" class="hidden" />
138- </Tabs>
139- </div>
140- <Show
141- when={contentView() === "write"}
142- fallback={
143- <div class="min-h-40 rounded-lg border border-input bg-background/80 p-3 text-sm leading-relaxed text-foreground [&_ol]:ml-5 [&_ol]:list-decimal [&_ul]:ml-5 [&_ul]:list-disc">
144- <Show when={content().trim()} fallback={<p class="text-muted-foreground">{t("notes.noContent")}</p>}>
145- <div innerHTML={content()} />
146- </Show>
147- </div>
148- }
149- >
150- <RichTextEditor
151- value={content()}
152- onChange={setContent}
153- placeholder={t("form.content")}
154- minHeight="min-h-40"
155- />
156- </Show>
126+ <div class="space-y-1.5">
127+ <Label>{t("form.content")}</Label>
128+ <NoteRichEditor
129+ value={content()}
130+ onChange={setContent}
131+ placeholder={t("notes.bodyPlaceholder")}
132+ toolbarClass="top-0"
133+ bodyClass="min-h-64"
134+ />
157135 </div>
158136
159137 <Show when={showFiles()}>
src/components/notes/note-list.tsxmodified+5 -2
@@ -13,6 +13,8 @@ export function NoteList(props: {
1313 canManage?: boolean;
1414 emptyTitle: string;
1515 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;
1618 onUpdate: (id: string, values: { title: string; content: string }) => Promise<void>;
1719 onDelete: (id: string) => Promise<void>;
1820 }) {
@@ -30,14 +32,15 @@ export function NoteList(props: {
3032 />
3133 }
3234 >
33- <ul class="grid grid-cols-2 gap-3 xl:grid-cols-3">
35+ <ul class="grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
3436 <For each={props.notes}>
3537 {(note) => (
3638 <li class="animate-fade-up">
3739 <NoteCard
3840 note={note}
3941 canManage={props.canManage}
40- onOpen={setReadingNote}
42+ onOpen={(item) => (props.onOpen ? props.onOpen(item) : setReadingNote(item))}
43+ onEdit={props.onOpen}
4144 onUpdate={props.onUpdate}
4245 onDelete={props.onDelete}
4346 />
src/components/notes/note-reader-panel.tsxmodified+8 -9
@@ -4,6 +4,7 @@ import type { NoteFileSource } from "@/lib/note-source";
44 import { NoteFilesPanel } from "@/components/notes/note-files-panel";
55 import { RagOutputsPanel } from "@/components/notes/rag-outputs-panel";
66 import { SidePanel } from "@/components/ui/side-panel";
7+import { toRichTextHtml } from "@/lib/rich-text";
78 import { useT } from "@/stores/preferences-context";
89
910 export function NoteReaderPanel(props: {
@@ -27,15 +28,13 @@ export function NoteReaderPanel(props: {
2728 <Show when={note()}>
2829 {(n) => (
2930 <div class="space-y-4">
30- <article class="overflow-hidden rounded-lg border border-amber-200/70 bg-[linear-gradient(90deg,rgba(245,158,11,0.14)_0,rgba(245,158,11,0.14)_3rem,transparent_3rem),repeating-linear-gradient(0deg,transparent_0,transparent_2.45rem,rgba(120,113,108,0.16)_2.5rem)] shadow-xs dark:border-amber-500/20 dark:bg-[linear-gradient(90deg,rgba(245,158,11,0.12)_0,rgba(245,158,11,0.12)_3rem,transparent_3rem),repeating-linear-gradient(0deg,transparent_0,transparent_2.45rem,rgba(214,211,209,0.12)_2.5rem)]">
31- <div class="min-h-80 space-y-4 px-5 py-5 pl-16">
32- <Show
33- when={note()?.content?.trim()}
34- fallback={<p class="text-sm italic leading-8 text-muted-foreground">{t("notes.noContent")}</p>}
35- >
36- <div class="whitespace-pre-wrap text-sm leading-8 text-foreground [&_ol]:ml-5 [&_ol]:list-decimal [&_ul]:ml-5 [&_ul]:list-disc" innerHTML={note()?.content ?? ""} />
37- </Show>
38- </div>
31+ <article class="rounded-xl border border-border bg-card px-5 py-5 shadow-xs sm:px-7">
32+ <Show
33+ when={note()?.content?.trim()}
34+ fallback={<p class="text-sm italic text-muted-foreground">{t("notes.noContent")}</p>}
35+ >
36+ <div class="note-prose" innerHTML={toRichTextHtml(note()?.content)} />
37+ </Show>
3938 </article>
4039 <NoteFilesPanel noteId={n().id} source={props.source} canManage={props.canManage} active={props.open} />
4140 <Show when={props.source.listRagOutputs}>
src/components/notes/note-rich-editor.tsxadded+250 -0
@@ -0,0 +1,250 @@
1+import { For, createSignal, onCleanup, onMount, type JSX } from "solid-js";
2+import { ConfirmDialog } from "@/components/ui/confirm-dialog";
3+import {
4+ IconArrowRedo,
5+ IconArrowUndo,
6+ IconBold,
7+ IconCodeBlock,
8+ IconHeading2,
9+ IconHeading3,
10+ IconItalic,
11+ IconLink,
12+ IconListBullets,
13+ IconListNumbers,
14+ IconParagraph,
15+ IconQuote,
16+ IconStrikethrough,
17+ IconUnderline,
18+} from "@/components/ui/icons";
19+import { cn } from "@/lib/cn";
20+import { isRichTextEmpty, sanitizeRichText, toRichTextHtml } from "@/lib/rich-text";
21+import { useT } from "@/stores/preferences-context";
22+
23+type Block = "p" | "h2" | "h3" | "blockquote" | "pre";
24+type InlineState = { bold: boolean; italic: boolean; underline: boolean; strikeThrough: boolean; ul: boolean; ol: boolean; block: Block };
25+
26+const IDLE: InlineState = { bold: false, italic: false, underline: false, strikeThrough: false, ul: false, ol: false, block: "p" };
27+
28+/**
29+ * Document-style note editor: a sticky formatting bar over a contentEditable
30+ * body that grows with its text (the page scrolls, not a small box). The body
31+ * is HTML — the format notes are stored in — and every paste and every value
32+ * loaded from the server is sanitized before it reaches the DOM.
33+ */
34+export function NoteRichEditor(props: {
35+ value: string;
36+ onChange: (html: string) => void;
37+ placeholder?: string;
38+ /** Sticky offset for the formatting bar, e.g. below the app header. */
39+ toolbarClass?: string;
40+ class?: string;
41+ /** Right side of the formatting bar — the page's save control lives here. */
42+ actions?: JSX.Element;
43+ /** Minimum body height; a full page wants most of the viewport, a side panel less. */
44+ bodyClass?: string;
45+}) {
46+ const t = useT();
47+ let body: HTMLDivElement | undefined;
48+ let savedRange: Range | null = null;
49+ const [state, setState] = createSignal<InlineState>(IDLE);
50+ const [empty, setEmpty] = createSignal(isRichTextEmpty(props.value));
51+ const [linkOpen, setLinkOpen] = createSignal(false);
52+ const [linkInitial, setLinkInitial] = createSignal("https://");
53+ const [linkText, setLinkText] = createSignal("");
54+
55+ const emit = () => {
56+ if (!body) return;
57+ const blank = isRichTextEmpty(body.innerHTML);
58+ setEmpty(blank);
59+ // A first line typed into an empty body is a bare text node. Store it as a
60+ // paragraph, so the value is recognisably HTML and its entities (`&lt;`)
61+ // are never mistaken for plain text and escaped twice on the next load.
62+ const html = body.firstElementChild ? body.innerHTML : `<p>${body.innerHTML}</p>`;
63+ props.onChange(blank ? "" : html);
64+ };
65+
66+ const selectionInside = () => {
67+ const selection = window.getSelection();
68+ return !!(body && selection && selection.rangeCount > 0 && body.contains(selection.anchorNode));
69+ };
70+
71+ const refreshState = () => {
72+ if (!selectionInside()) return;
73+ const block = String(document.queryCommandValue("formatBlock") || "p").toLowerCase().replace(/[<>]/g, "");
74+ setState({
75+ bold: document.queryCommandState("bold"),
76+ italic: document.queryCommandState("italic"),
77+ underline: document.queryCommandState("underline"),
78+ strikeThrough: document.queryCommandState("strikeThrough"),
79+ ul: document.queryCommandState("insertUnorderedList"),
80+ ol: document.queryCommandState("insertOrderedList"),
81+ block: (["h2", "h3", "blockquote", "pre"].includes(block) ? block : "p") as Block,
82+ });
83+ };
84+
85+ const run = (command: string, value?: string) => {
86+ body?.focus();
87+ document.execCommand(command, false, value);
88+ emit();
89+ refreshState();
90+ };
91+
92+ // Clicking the active block style again returns the line to a paragraph.
93+ const toggleBlock = (block: Block) => run("formatBlock", `<${state().block === block ? "p" : block}>`);
94+
95+ onMount(() => {
96+ if (!body) return;
97+ body.innerHTML = toRichTextHtml(props.value);
98+ const onSelection = () => refreshState();
99+ document.addEventListener("selectionchange", onSelection);
100+ onCleanup(() => document.removeEventListener("selectionchange", onSelection));
101+ });
102+
103+ const openLink = () => {
104+ const selection = window.getSelection();
105+ savedRange = selectionInside() && selection ? selection.getRangeAt(0).cloneRange() : null;
106+ const anchor = selection?.anchorNode?.parentElement?.closest("a");
107+ setLinkInitial(anchor?.getAttribute("href") ?? "https://");
108+ setLinkText(savedRange?.toString().trim() || anchor?.textContent?.trim() || "—");
109+ setLinkOpen(true);
110+ };
111+
112+ const applyLink = (raw: string | undefined) => {
113+ body?.focus();
114+ const selection = window.getSelection();
115+ if (savedRange && selection) {
116+ selection.removeAllRanges();
117+ selection.addRange(savedRange);
118+ }
119+ const value = raw?.trim() ?? "";
120+ if (!value || value === "https://") return run("unlink");
121+ const href = /^(https?:|mailto:)/i.test(value) ? value : `https://${value}`;
122+ if (selection?.isCollapsed) {
123+ const link = document.createElement("a");
124+ link.href = href;
125+ link.textContent = value;
126+ run("insertHTML", sanitizeRichText(link.outerHTML));
127+ } else {
128+ run("createLink", href);
129+ }
130+ };
131+
132+ const onKeyDown = (event: KeyboardEvent) => {
133+ const mod = event.metaKey || event.ctrlKey;
134+ if (mod && !event.shiftKey && event.key.toLowerCase() === "k") {
135+ // Inside the body ⌘K means "link"; stop it before the window-level
136+ // command palette listener opens on top of the link dialog.
137+ event.preventDefault();
138+ event.stopPropagation();
139+ openLink();
140+ } else if (event.key === "Tab" && (state().ul || state().ol)) {
141+ event.preventDefault();
142+ run(event.shiftKey ? "outdent" : "indent");
143+ }
144+ };
145+
146+ const onPaste = (event: ClipboardEvent) => {
147+ const data = event.clipboardData;
148+ if (!data) return;
149+ event.preventDefault();
150+ const html = data.getData("text/html");
151+ if (html) run("insertHTML", sanitizeRichText(html));
152+ else run("insertText", data.getData("text/plain"));
153+ };
154+
155+ type Tool = { label: () => string; icon: (p: { class?: string }) => JSX.Element; active?: () => boolean; onClick: () => void };
156+ const groups: Tool[][] = [
157+ [
158+ { label: () => t("editor.undo"), icon: IconArrowUndo, onClick: () => run("undo") },
159+ { label: () => t("editor.redo"), icon: IconArrowRedo, onClick: () => run("redo") },
160+ ],
161+ [
162+ { label: () => t("editor.paragraph"), icon: IconParagraph, active: () => state().block === "p" && !state().ul && !state().ol, onClick: () => run("formatBlock", "<p>") },
163+ { label: () => t("editor.heading2"), icon: IconHeading2, active: () => state().block === "h2", onClick: () => toggleBlock("h2") },
164+ { label: () => t("editor.heading3"), icon: IconHeading3, active: () => state().block === "h3", onClick: () => toggleBlock("h3") },
165+ ],
166+ [
167+ { label: () => t("editor.bold"), icon: IconBold, active: () => state().bold, onClick: () => run("bold") },
168+ { label: () => t("editor.italic"), icon: IconItalic, active: () => state().italic, onClick: () => run("italic") },
169+ { label: () => t("editor.underline"), icon: IconUnderline, active: () => state().underline, onClick: () => run("underline") },
170+ { label: () => t("editor.strike"), icon: IconStrikethrough, active: () => state().strikeThrough, onClick: () => run("strikeThrough") },
171+ { label: () => t("editor.link"), icon: IconLink, onClick: openLink },
172+ ],
173+ [
174+ { label: () => t("editor.bulletList"), icon: IconListBullets, active: () => state().ul, onClick: () => run("insertUnorderedList") },
175+ { label: () => t("editor.numberedList"), icon: IconListNumbers, active: () => state().ol, onClick: () => run("insertOrderedList") },
176+ { label: () => t("editor.quote"), icon: IconQuote, active: () => state().block === "blockquote", onClick: () => toggleBlock("blockquote") },
177+ { label: () => t("editor.codeBlock"), icon: IconCodeBlock, active: () => state().block === "pre", onClick: () => toggleBlock("pre") },
178+ ],
179+ ];
180+
181+ return (
182+ <div class={cn("rounded-xl border border-border bg-card shadow-xs", props.class)}>
183+ <div class={cn("sticky z-20 flex items-center gap-2 rounded-t-xl border-b border-border bg-card/95 px-2 py-1.5 backdrop-blur", props.toolbarClass)}>
184+ {/* One row at every width: the tools scroll sideways on a phone so the
185+ save control on the right never wraps out of reach. */}
186+ <div class="flex min-w-0 flex-1 items-center gap-1 overflow-x-auto">
187+ <For each={groups}>
188+ {(group, index) => (
189+ <>
190+ <div class={cn("h-5 w-px shrink-0 bg-border", index() === 0 && "hidden")} />
191+ <div class="flex items-center gap-0.5">
192+ <For each={group}>
193+ {(tool) => (
194+ <button
195+ type="button"
196+ class={cn(
197+ "flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring",
198+ tool.active?.() && "bg-primary/10 text-primary hover:bg-primary/15 hover:text-primary",
199+ )}
200+ title={tool.label()}
201+ aria-label={tool.label()}
202+ aria-pressed={tool.active ? tool.active() : undefined}
203+ // Keep the caret in the body: a focused button would drop the selection.
204+ onMouseDown={(event) => event.preventDefault()}
205+ onClick={tool.onClick}
206+ >
207+ {tool.icon({ class: "h-4 w-4" })}
208+ </button>
209+ )}
210+ </For>
211+ </div>
212+ </>
213+ )}
214+ </For>
215+ </div>
216+ <div class="flex shrink-0 items-center gap-2">{props.actions}</div>
217+ </div>
218+ <div class="relative px-5 py-5 sm:px-8 sm:py-7">
219+ <div
220+ ref={body}
221+ role="textbox"
222+ aria-multiline="true"
223+ aria-label={props.placeholder}
224+ contentEditable
225+ class={cn("note-prose outline-hidden", props.bodyClass ?? "min-h-[max(55vh,320px)]")}
226+ data-empty={empty() ? "true" : "false"}
227+ data-placeholder={props.placeholder ?? ""}
228+ onFocus={() => document.execCommand("defaultParagraphSeparator", false, "p")}
229+ onInput={emit}
230+ onKeyDown={onKeyDown}
231+ onPaste={onPaste}
232+ onKeyUp={refreshState}
233+ onMouseUp={refreshState}
234+ />
235+ </div>
236+
237+ <ConfirmDialog
238+ open={linkOpen()}
239+ onOpenChange={setLinkOpen}
240+ title={t("editor.linkTitle")}
241+ description={t("editor.linkHint")}
242+ summary={linkText()}
243+ confirmLabel={t("common.save")}
244+ icon={<IconLink class="h-4 w-4" />}
245+ prompt={{ label: t("editor.linkUrl"), initialValue: linkInitial(), singleLine: true, maxLength: 2000 }}
246+ onConfirm={applyLink}
247+ />
248+ </div>
249+ );
250+}
src/components/ui/icons.tsxmodified+70 -0
@@ -49,6 +49,20 @@ import waveformUrl from "@phosphor-icons/core/regular/waveform.svg?url";
4949 import wifiHighUrl from "@phosphor-icons/core/regular/wifi-high.svg?url";
5050 import wifiSlashUrl from "@phosphor-icons/core/regular/wifi-slash.svg?url";
5151 import xUrl from "@phosphor-icons/core/regular/x.svg?url";
52+import textBUrl from "@phosphor-icons/core/regular/text-b.svg?url";
53+import textItalicUrl from "@phosphor-icons/core/regular/text-italic.svg?url";
54+import textUnderlineUrl from "@phosphor-icons/core/regular/text-underline.svg?url";
55+import textStrikethroughUrl from "@phosphor-icons/core/regular/text-strikethrough.svg?url";
56+import textHTwoUrl from "@phosphor-icons/core/regular/text-h-two.svg?url";
57+import textHThreeUrl from "@phosphor-icons/core/regular/text-h-three.svg?url";
58+import textTUrl from "@phosphor-icons/core/regular/text-t.svg?url";
59+import listBulletsUrl from "@phosphor-icons/core/regular/list-bullets.svg?url";
60+import listNumbersUrl from "@phosphor-icons/core/regular/list-numbers.svg?url";
61+import quotesUrl from "@phosphor-icons/core/regular/quotes.svg?url";
62+import codeBlockUrl from "@phosphor-icons/core/regular/code-block.svg?url";
63+import linkSimpleUrl from "@phosphor-icons/core/regular/link-simple.svg?url";
64+import arrowUUpLeftUrl from "@phosphor-icons/core/regular/arrow-u-up-left.svg?url";
65+import arrowUUpRightUrl from "@phosphor-icons/core/regular/arrow-u-up-right.svg?url";
5266
5367 type IconProps = {
5468 class?: string;
@@ -646,3 +660,59 @@ export function IconWifi(props: IconProps) {
646660 export function IconWifiOff(props: IconProps) {
647661 return <PhosphorIcon {...props} src={wifiSlashUrl} />;
648662 }
663+
664+export function IconBold(props: IconProps) {
665+ return <PhosphorIcon {...props} src={textBUrl} />;
666+}
667+
668+export function IconItalic(props: IconProps) {
669+ return <PhosphorIcon {...props} src={textItalicUrl} />;
670+}
671+
672+export function IconUnderline(props: IconProps) {
673+ return <PhosphorIcon {...props} src={textUnderlineUrl} />;
674+}
675+
676+export function IconStrikethrough(props: IconProps) {
677+ return <PhosphorIcon {...props} src={textStrikethroughUrl} />;
678+}
679+
680+export function IconHeading2(props: IconProps) {
681+ return <PhosphorIcon {...props} src={textHTwoUrl} />;
682+}
683+
684+export function IconHeading3(props: IconProps) {
685+ return <PhosphorIcon {...props} src={textHThreeUrl} />;
686+}
687+
688+export function IconParagraph(props: IconProps) {
689+ return <PhosphorIcon {...props} src={textTUrl} />;
690+}
691+
692+export function IconListBullets(props: IconProps) {
693+ return <PhosphorIcon {...props} src={listBulletsUrl} />;
694+}
695+
696+export function IconListNumbers(props: IconProps) {
697+ return <PhosphorIcon {...props} src={listNumbersUrl} />;
698+}
699+
700+export function IconQuote(props: IconProps) {
701+ return <PhosphorIcon {...props} src={quotesUrl} />;
702+}
703+
704+export function IconCodeBlock(props: IconProps) {
705+ return <PhosphorIcon {...props} src={codeBlockUrl} />;
706+}
707+
708+export function IconLink(props: IconProps) {
709+ return <PhosphorIcon {...props} src={linkSimpleUrl} />;
710+}
711+
712+export function IconArrowUndo(props: IconProps) {
713+ return <PhosphorIcon {...props} src={arrowUUpLeftUrl} />;
714+}
715+
716+export function IconArrowRedo(props: IconProps) {
717+ return <PhosphorIcon {...props} src={arrowUUpRightUrl} />;
718+}
src/i18n/messages.tsmodified+69 -0
@@ -152,6 +152,29 @@ export type MessageKey =
152152 | "editor.numberedListLabel"
153153 | "editor.clearFormattingLabel"
154154 | "editor.bodyPlaceholder"
155+ | "editor.paragraph"
156+ | "editor.heading2"
157+ | "editor.heading3"
158+ | "editor.quote"
159+ | "editor.codeBlock"
160+ | "editor.link"
161+ | "editor.linkTitle"
162+ | "editor.linkHint"
163+ | "editor.linkUrl"
164+ | "editor.undo"
165+ | "editor.redo"
166+ | "notes.backToNotebook"
167+ | "notes.titlePlaceholder"
168+ | "notes.bodyPlaceholder"
169+ | "notes.saveShortcut"
170+ | "notes.unsaved"
171+ | "notes.allSaved"
172+ | "notes.saving"
173+ | "notes.leaveTitle"
174+ | "notes.leaveHint"
175+ | "notes.leaveConfirm"
176+ | "notes.filesAfterSave"
177+ | "notes.open"
155178 | "messages.refreshList"
156179 | "messages.deleteDraft"
157180 | "messages.restoreFromTrash"
@@ -2045,6 +2068,29 @@ const en: Dict = {
20452068 "editor.numberedListLabel": "1. List",
20462069 "editor.clearFormattingLabel": "Clear format",
20472070 "editor.bodyPlaceholder": "Write your message here…",
2071+ "editor.paragraph": "Paragraph",
2072+ "editor.heading2": "Heading",
2073+ "editor.heading3": "Subheading",
2074+ "editor.quote": "Quote",
2075+ "editor.codeBlock": "Code block",
2076+ "editor.link": "Link (Ctrl+K)",
2077+ "editor.linkTitle": "Add a link",
2078+ "editor.linkHint": "Leave the address empty to remove the link.",
2079+ "editor.linkUrl": "Address",
2080+ "editor.undo": "Undo",
2081+ "editor.redo": "Redo",
2082+ "notes.backToNotebook": "Notebook",
2083+ "notes.titlePlaceholder": "Untitled note",
2084+ "notes.bodyPlaceholder": "Start writing…",
2085+ "notes.saveShortcut": "{key}+S to save",
2086+ "notes.unsaved": "Unsaved changes",
2087+ "notes.allSaved": "All changes saved",
2088+ "notes.saving": "Saving…",
2089+ "notes.leaveTitle": "Leave without saving?",
2090+ "notes.leaveHint": "Your unsaved changes to this note will be lost.",
2091+ "notes.leaveConfirm": "Leave",
2092+ "notes.filesAfterSave": "Save the note first, then attach files and drawings here.",
2093+ "notes.open": "Open",
20482094 "messages.refreshList": "Refresh messages",
20492095 "messages.deleteDraft": "Delete draft",
20502096 "messages.restoreFromTrash": "Restore from trash",
@@ -3946,6 +3992,29 @@ const tr: Dict = {
39463992 "editor.numberedListLabel": "1. Liste",
39473993 "editor.clearFormattingLabel": "Biçimi temizle",
39483994 "editor.bodyPlaceholder": "Mesajınızı buraya yazın…",
3995+ "editor.paragraph": "Paragraf",
3996+ "editor.heading2": "Başlık",
3997+ "editor.heading3": "Alt başlık",
3998+ "editor.quote": "Alıntı",
3999+ "editor.codeBlock": "Kod bloğu",
4000+ "editor.link": "Bağlantı (Ctrl+K)",
4001+ "editor.linkTitle": "Bağlantı ekle",
4002+ "editor.linkHint": "Bağlantıyı kaldırmak için adresi boş bırak.",
4003+ "editor.linkUrl": "Adres",
4004+ "editor.undo": "Geri al",
4005+ "editor.redo": "Yinele",
4006+ "notes.backToNotebook": "Defter",
4007+ "notes.titlePlaceholder": "Başlıksız not",
4008+ "notes.bodyPlaceholder": "Yazmaya başla…",
4009+ "notes.saveShortcut": "Kaydetmek için {key}+S",
4010+ "notes.unsaved": "Kaydedilmemiş değişiklikler",
4011+ "notes.allSaved": "Tüm değişiklikler kaydedildi",
4012+ "notes.saving": "Kaydediliyor…",
4013+ "notes.leaveTitle": "Kaydetmeden çıkılsın mı?",
4014+ "notes.leaveHint": "Bu nottaki kaydedilmemiş değişiklikler kaybolacak.",
4015+ "notes.leaveConfirm": "Çık",
4016+ "notes.filesAfterSave": "Önce notu kaydet, sonra buraya dosya ve çizim ekleyebilirsin.",
4017+ "notes.open": "Aç",
39494018 "messages.refreshList": "Mesajları yenile",
39504019 "messages.deleteDraft": "Taslağı sil",
39514020 "messages.restoreFromTrash": "Çöp kutusundan çıkar",
src/index.cssmodified+50 -0
@@ -555,3 +555,53 @@
555555 linear-gradient(120deg, hsl(var(--primary) / 0.28), transparent 65%);
556556 background-size: 8px 8px, 8px 8px, 100% 100%;
557557 }
558+
559+/* Note bodies: the stored HTML from the note editor, read or edited. One
560+ stylesheet for both keeps what you type identical to what you read. */
561+@layer components {
562+ .note-prose {
563+ color: hsl(var(--foreground));
564+ font-size: 0.95rem;
565+ line-height: 1.75;
566+ overflow-wrap: anywhere;
567+ }
568+ .note-prose > * + * { margin-top: 0.75em; }
569+ .note-prose h2 { margin-top: 1.4em; font-size: 1.4rem; font-weight: 650; line-height: 1.3; letter-spacing: -0.01em; }
570+ .note-prose h3 { margin-top: 1.2em; font-size: 1.12rem; font-weight: 650; line-height: 1.35; }
571+ .note-prose > :first-child { margin-top: 0; }
572+ .note-prose ul { padding-left: 1.4em; list-style: disc; }
573+ .note-prose ol { padding-left: 1.4em; list-style: decimal; }
574+ .note-prose li + li { margin-top: 0.25em; }
575+ .note-prose li::marker { color: hsl(var(--muted-foreground)); }
576+ .note-prose blockquote {
577+ border-left: 3px solid hsl(var(--primary) / 0.55);
578+ padding-left: 1em;
579+ color: hsl(var(--muted-foreground));
580+ }
581+ .note-prose pre {
582+ border: 1px solid hsl(var(--border));
583+ border-radius: 0.5rem;
584+ background: hsl(var(--muted) / 0.6);
585+ padding: 0.75em 1em;
586+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
587+ font-size: 0.85rem;
588+ line-height: 1.6;
589+ white-space: pre-wrap;
590+ }
591+ .note-prose code {
592+ border-radius: 0.3rem;
593+ background: hsl(var(--muted) / 0.8);
594+ padding: 0.1em 0.35em;
595+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
596+ font-size: 0.85em;
597+ }
598+ .note-prose pre code { background: transparent; padding: 0; }
599+ .note-prose a { color: hsl(var(--primary)); text-decoration: underline; text-underline-offset: 2px; }
600+ /* Placeholder for an empty contentEditable body. */
601+ .note-prose[data-empty="true"]::before {
602+ content: attr(data-placeholder);
603+ color: hsl(var(--muted-foreground) / 0.7);
604+ pointer-events: none;
605+ position: absolute;
606+ }
607+}
src/pages/note-editor-page.tsxadded+31 -0
@@ -0,0 +1,31 @@
1+import { useLocation } from "@tanstack/solid-router";
2+import { Show, Suspense, createMemo } from "solid-js";
3+import { getNoteById } from "@/api/notes";
4+import { formatApiError } from "@/api/client";
5+import { RouteGuard } from "@/components/layout/route-guard";
6+import { NoteDocument } from "@/components/notes/note-document";
7+import { ErrorAlert } from "@/components/ui/error-alert";
8+import { PageSpinner } from "@/components/ui/page-spinner";
9+import { createResource } from "@/lib/create-resource";
10+
11+/** `/notes/new` and `/notes/$id` — the router remounts this page per note. */
12+export default function NoteEditorPage() {
13+ const location = useLocation();
14+ const id = createMemo(() => {
15+ const match = /^\/notes\/([^/]+)$/.exec(location().pathname);
16+ return match && match[1] !== "new" ? decodeURIComponent(match[1]) : null;
17+ });
18+ const [note, { refetch }] = createResource(id, (noteId) => getNoteById(noteId));
19+
20+ return (
21+ <RouteGuard>
22+ <Show when={id()} fallback={<NoteDocument />}>
23+ <Suspense fallback={<PageSpinner />}>
24+ <Show when={!note.error} fallback={<ErrorAlert message={formatApiError(note.error)} onRetry={() => void refetch()} />}>
25+ <Show when={note()}>{(loaded) => <NoteDocument note={loaded()} />}</Show>
26+ </Show>
27+ </Suspense>
28+ </Show>
29+ </RouteGuard>
30+ );
31+}
src/pages/notes-page.tsxmodified+7 -37
@@ -1,16 +1,14 @@
11 import { Show, Suspense, createEffect, createMemo, createSignal } from "solid-js";
22 import { createResource } from "@/lib/create-resource";
3-import { useLocation } from "@tanstack/solid-router";
3+import { useLocation, useNavigate } from "@tanstack/solid-router";
44 import { deleteNoteById } from "@/api/notes";
55 import { getNotes } from "@/api/notes";
66 import { patchNoteById } from "@/api/notes";
77 import { postNote } from "@/api/notes";
8-import { postNoteFile } from "@/api/notes";
98 import { formatApiError } from "@/api/client";
109 import { Alert } from "@/components/ui/alert";
1110 import { RouteGuard } from "@/components/layout/route-guard";
1211 import { DataSection } from "@/components/ui/data-section";
13-import { NoteForm } from "@/components/notes/note-form";
1412 import { NoteImportPanel } from "@/components/notes/note-import-panel";
1513 import { NoteList } from "@/components/notes/note-list";
1614 import { Button } from "@/components/ui/button";
@@ -36,12 +34,13 @@ export default function NotesPage() {
3634 function NotesContent() {
3735 const t = useT();
3836 const location = useLocation();
37+ const navigate = useNavigate();
3938 const [error, setError] = createSignal("");
4039 const [flash, setFlash] = createFlash();
41- const [createOpen, setCreateOpen] = createSignal(location().searchStr.includes("action=new"));
4240 const [importOpen, setImportOpen] = createSignal(location().searchStr.includes("action=import"));
4341 createEffect(() => {
44- if (location().searchStr.includes("action=new")) setCreateOpen(true);
42+ // Old deep link: the new-note side panel is now its own page.
43+ if (location().searchStr.includes("action=new")) void navigate({ to: "/notes/new", replace: true });
4544 if (location().searchStr.includes("action=import")) setImportOpen(true);
4645 });
4746 const [page, setPage] = createSignal(0);
@@ -91,43 +90,13 @@ function NotesContent() {
9190 />
9291 </SidePanel>
9392
94- <SidePanel open={createOpen()} onOpenChange={setCreateOpen} title={t("notes.new")}>
95- <NoteForm
96- enableFiles
97- submitLabel={t("common.create")}
98- onCancel={() => setCreateOpen(false)}
99- onSubmit={async (values) => {
100- setError("");
101- const note = await postNote({
102- title: values.title,
103- content: values.content || undefined,
104- });
105- let failedUploads = 0;
106- for (const file of values.files) {
107- try {
108- await postNoteFile(note.id, file);
109- } catch {
110- failedUploads += 1;
111- }
112- }
113- await refetch();
114- setCreateOpen(false);
115- if (failedUploads > 0) {
116- setError(t("notes.fileUploadPartial", { count: failedUploads }));
117- return;
118- }
119- setFlash(t("common.created"));
120- }}
121- />
122- </SidePanel>
123-
12493 <div class="space-y-5">
12594 <DataSection
12695 title={t("notes.title")}
12796 description={t("notes.subtitle")}
12897 actions={
12998 <div class="flex items-center gap-2">
130- <Button type="button" size="sm" class="min-w-[7.5rem] rounded-lg" onClick={() => setCreateOpen(true)}>
99+ <Button type="button" size="sm" class="min-w-[7.5rem] rounded-lg" onClick={() => void navigate({ to: "/notes/new" })}>
131100 <IconPlus class="h-4 w-4" />
132101 {t("notes.new")}
133102 </Button>
@@ -141,7 +110,7 @@ function NotesContent() {
141110 <Show when={flash()}>
142111 <Alert variant="success">{flash()}</Alert>
143112 </Show>
144- <Show when={error() && !createOpen() && !importOpen()}>
113+ <Show when={error() && !importOpen()}>
145114 <Alert variant="destructive">{error()}</Alert>
146115 </Show>
147116 <Suspense fallback={<PageSpinner />}>
@@ -152,6 +121,7 @@ function NotesContent() {
152121 <NoteList
153122 notes={pageItems()}
154123 source={personalNoteFiles}
124+ onOpen={(note) => void navigate({ to: "/notes/$id", params: { id: note.id } })}
155125 emptyTitle={t("dashboard.emptyNotesTitle")}
156126 emptyDescription={t("notes.empty")}
157127 onUpdate={(id, values) =>
src/routes/router.tsxmodified+15 -0
@@ -28,6 +28,7 @@ const LoginPage = lazyRoute(() => import("@/pages/login-page"));
2828 const RegisterPage = lazyRoute(() => import("@/pages/register-page"));
2929 const DashboardPage = lazyRoute(() => import("@/pages/dashboard-page"));
3030 const NotesPage = lazyRoute(() => import("@/pages/notes-page"));
31+const NoteEditorPage = lazyRoute(() => import("@/pages/note-editor-page"));
3132 const EventsPage = lazyRoute(() => import("@/pages/events-page"));
3233 const EventDetailPage = lazyRoute(() => import("@/pages/event-detail-page"));
3334 const HomeworkPage = lazyRoute(() => import("@/pages/homework-page"));
@@ -118,6 +119,18 @@ const notesRoute = createRoute({
118119 component: NotesPage,
119120 });
120121
122+const noteNewRoute = createRoute({
123+ getParentRoute: () => rootRoute,
124+ path: "/notes/new",
125+ component: NoteEditorPage,
126+});
127+
128+const noteDetailRoute = createRoute({
129+ getParentRoute: () => rootRoute,
130+ path: "/notes/$id",
131+ component: NoteEditorPage,
132+});
133+
121134 const eventsRoute = createRoute({
122135 getParentRoute: () => rootRoute,
123136 path: "/events",
@@ -482,6 +495,8 @@ const routeTree = rootRoute.addChildren([
482495 loginRoute,
483496 registerRoute,
484497 notesRoute,
498+ noteNewRoute,
499+ noteDetailRoute,
485500 eventsRoute,
486501 eventDetailRoute,
487502 homeworkRoute,