From 16702c4d6a94ae19d276fd912006d12f9a78b67a Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Tue, 8 Aug 2023 00:11:15 +0200 Subject: [PATCH] Fix out-of-order antenna note pagination --- .../src/server/api/endpoints/antennas/notes.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/antennas/notes.ts b/packages/backend/src/server/api/endpoints/antennas/notes.ts index d48503237..a96c16e9a 100644 --- a/packages/backend/src/server/api/endpoints/antennas/notes.ts +++ b/packages/backend/src/server/api/endpoints/antennas/notes.ts @@ -126,17 +126,25 @@ export default define(meta, paramDef, async (ps, user) => { readNote(user.id, notes); } + const packedNotes = (await Notes.packMany(notes, user)).sort( + (a, b) => + paginationMap.findIndex((p) => p[0] == a.id) - + paginationMap.findIndex((p) => p[0] == b.id), + ); + if (notes.length < ps.limit) { pagination = "-1"; } else { // I'm so sorry, FIXME: rewrite pagination system pagination = paginationMap.find( - (p) => p[0] == notes[notes.length - (notes.length > 1 ? 2 : 1)].id, + (p) => + p[0] == + packedNotes[packedNotes.length - (packedNotes.length > 1 ? 2 : 1)].id, )[1]; } return { pagination: pagination, - notes: await Notes.packMany(notes, user), + notes: packedNotes, }; });