Workflow-App/Workflow/app/notes/page.tsx

59 lines
2 KiB
TypeScript
Raw Permalink Normal View History

2026-09-16 12:28:52 +00:00
// app/notes/page.tsx
// Server Component. Loads all notes from PocketBase and hands them to
// the Client Component <NotesList> which owns the CRUD UI state.
//
// Notes live in the ysterbaard_notes collection. If the collection is
// missing (PB returns 404) or any other load error happens, the page
// renders an inline error banner instead of crashing with a generic 500.
2026-09-16 12:28:52 +00:00
import { fetchCollection } from "@/lib/pb";
import type { YsterbaardNote } from "@/lib/types";
import PageHeader from "@/components/PageHeader";
import NotesList from "./NotesList";
export const dynamic = "force-dynamic";
async function loadNotes(): Promise<{ notes: YsterbaardNote[]; error: string | null }> {
2026-09-16 12:28:52 +00:00
try {
const list = await fetchCollection<YsterbaardNote>("ysterbaard_notes", {
page: 1,
perPage: 500,
sort: "-id",
2026-09-16 12:28:52 +00:00
});
return { notes: list.items ?? [], error: null };
2026-09-16 12:28:52 +00:00
} catch (err) {
const msg = err instanceof Error ? err.message : "Unknown PB error";
if (msg.includes("404") || msg.toLowerCase().includes("not found")) {
return {
notes: [],
error:
"The ysterbaard_notes collection is missing on PocketBase. " +
2026-09-16 12:28:52 +00:00
"Open https://pb.agent.apphub.co.za/_/ and create it before " +
"using this tab. See docs/superpowers/specs/2026-09-16-notes-tab-design.md for the field spec.",
};
2026-09-16 12:28:52 +00:00
}
return { notes: [], error: `Could not load notes: ${msg}` };
2026-09-16 12:28:52 +00:00
}
}
export default async function NotesPage() {
const { notes, error } = await loadNotes();
2026-09-16 12:28:52 +00:00
return (
<>
<PageHeader
eyebrow="Quick notes"
title="Notes"
subtitle="Things to do. Tick when done, edit, or delete."
/>
{error ? (
<div className="container-x py-6">
<div className="rounded-md border border-amber-300 bg-amber-50 text-amber-900 px-4 py-3 text-sm whitespace-pre-line">
{error}
</div>
</div>
) : (
<NotesList initialNotes={notes} />
)}
2026-09-16 12:28:52 +00:00
</>
);
}