fix(notes): sort by -id instead of -created (PB 400 on fresh collection sort=created)
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.
This commit is contained in:
parent
e934770a03
commit
f5c7960c6f
2 changed files with 7 additions and 6 deletions
|
|
@ -20,19 +20,20 @@ export default function NotesList({ initialNotes }: Props) {
|
|||
const [editingId, setEditingId] = useState<string | null>(null);
|
||||
const [error, setError] = useState<string | null>(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]);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ async function loadNotes(): Promise<{ notes: YsterbaardNote[]; error: string | n
|
|||
const list = await fetchCollection<YsterbaardNote>("ysterbaard_notes", {
|
||||
page: 1,
|
||||
perPage: 500,
|
||||
sort: "-created",
|
||||
sort: "-id",
|
||||
});
|
||||
return { notes: list.items ?? [], error: null };
|
||||
} catch (err) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue