From d3a625e084e05a4d3301ae6c1ace8cf3179db16d Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Sun, 7 Apr 2024 16:32:45 -1000 Subject: [PATCH] Fix pagination bug --- utils/timelines.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/timelines.ts b/utils/timelines.ts index c322dbdc..84581f7f 100644 --- a/utils/timelines.ts +++ b/utils/timelines.ts @@ -5,6 +5,8 @@ export async function fetchTimeline( args: Prisma.StatusFindManyArgs | Prisma.UserFindManyArgs, req: Request, ) { + // BEFORE: Before in a top-to-bottom order, so the most recent posts + // AFTER: After in a top-to-bottom order, so the oldest posts // @ts-expect-error This is a hack to get around the fact that Prisma doesn't have a common base type for all models const objects = (await model.findMany(args)) as T[]; @@ -49,9 +51,7 @@ export async function fetchTimeline( const urlWithoutQuery = req.url.split("?")[0]; // Add next link linkHeader.push( - `<${urlWithoutQuery}?max_id=${ - objects.at(-1)?.id - }>; rel="next"`, + `<${urlWithoutQuery}?max_id=${objectsAfter[0].id}>; rel="next"`, ); } }