forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

note-editor-page.tsx31 lines, 1.3 KiBHistoryRawDownload
1import { useLocation } from "@tanstack/solid-router";
2import { Show, Suspense, createMemo } from "solid-js";
3import { getNoteById } from "@/api/notes";
4import { formatApiError } from "@/api/client";
5import { RouteGuard } from "@/components/layout/route-guard";
6import { NoteDocument } from "@/components/notes/note-document";
7import { ErrorAlert } from "@/components/ui/error-alert";
8import { PageSpinner } from "@/components/ui/page-spinner";
9import { createResource } from "@/lib/create-resource";
10
11/** `/notes/new` and `/notes/$id` — the router remounts this page per note. */
12export 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}