Connect, collaborate, and grow with a community of TypeScript developers
fix: notification pagination
bautistaaa833ec0d5e1d6
diff --git a/apps/web/src/app/notifications/notification.actions.ts b/apps/web/src/app/notifications/notification.actions.tsindex 06e0873d..5a60dbc7 100644--- a/apps/web/src/app/notifications/notification.actions.ts+++ b/apps/web/src/app/notifications/notification.actions.ts@@ -77,8 +77,45 @@ export async function getNotifications({{createdAt: 'desc',},+ {+ id: 'desc',+ },+ ],+ });++ if (notifications.length === 0) {+ return {+ notifications: [],+ cursor: undefined,+ };+ }++ const nextPage = await prisma.notification.findMany({+ take: 1,+ skip: 1,+ cursor: { id: notifications.at(-1)?.id },+ where: {+ toUserId: session.user.id,+ type: mentionsOnly ? 'MENTION' : undefined,+ },+ select: {+ id: true,+ },+ orderBy: [+ {+ isRead: 'asc',+ },+ {+ createdAt: 'desc',+ },+ {+ id: 'desc',+ },],});- return { notifications, cursor: notifications.at(-1)?.id };+ return {+ notifications,+ cursor: nextPage.length > 0 ? notifications.at(-1)?.id : undefined,+ };}