hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 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 | } |