From f5c7960c6f43e3051a1f87d40c2659132b7694ea Mon Sep 17 00:00:00 2001 From: sjcoetzeesj-coder Date: Thu, 17 Sep 2026 13:19:15 +0200 Subject: [PATCH] fix(notes): sort by -id instead of -created (PB 400 on fresh collection sort=created) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PB returns 400 when sorting a freshly imported collection by autodate system fields (created, updated) — those fields aren't yet exposed for sorting. id always works. --- Workflow/app/notes/NotesList.tsx | 11 ++++++----- Workflow/app/notes/page.tsx | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Workflow/app/notes/NotesList.tsx b/Workflow/app/notes/NotesList.tsx index 2edb092..a3a4143 100644 --- a/Workflow/app/notes/NotesList.tsx +++ b/Workflow/app/notes/NotesList.tsx @@ -20,19 +20,20 @@ export default function NotesList({ initialNotes }: Props) { const [editingId, setEditingId] = useState(null); const [error, setError] = useState(null); - // Sort: open first (created desc), then done (done_at desc). + // Sort: open first (id desc — newest first), then done (done_at desc, fallback id desc). const sorted = useMemo(() => { const open = notes .filter((n) => !n.is_done) .slice() - .sort((a, b) => (a.created < b.created ? 1 : -1)); + .sort((a, b) => (a.id < b.id ? 1 : -1)); const done = notes .filter((n) => n.is_done) .slice() .sort((a, b) => { - const ad = a.done_at ?? a.updated ?? a.created; - const bd = b.done_at ?? b.updated ?? b.created; - return ad < bd ? 1 : -1; + const ad = a.done_at ?? ""; + const bd = b.done_at ?? ""; + if (ad !== bd) return ad < bd ? 1 : -1; + return a.id < b.id ? 1 : -1; }); return [...open, ...done]; }, [notes]); diff --git a/Workflow/app/notes/page.tsx b/Workflow/app/notes/page.tsx index ad1b646..6740270 100644 --- a/Workflow/app/notes/page.tsx +++ b/Workflow/app/notes/page.tsx @@ -18,7 +18,7 @@ async function loadNotes(): Promise<{ notes: YsterbaardNote[]; error: string | n const list = await fetchCollection("ysterbaard_notes", { page: 1, perPage: 500, - sort: "-created", + sort: "-id", }); return { notes: list.items ?? [], error: null }; } catch (err) {