Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

Fix: Comment pagination is broken (#468)

Maxwell DeMaio716473fa64ad
diff --git a/apps/web/src/app/challenge/_components/comments/getCommentRouteData.ts b/apps/web/src/app/challenge/_components/comments/getCommentRouteData.ts
index 60aac2cb..f2cf1297 100644
--- a/apps/web/src/app/challenge/_components/comments/getCommentRouteData.ts
+++ b/apps/web/src/app/challenge/_components/comments/getCommentRouteData.ts
@@ -19,6 +19,7 @@ export async function getPaginatedComments({
parentId?: number | null;
}) {
const session = await getServerAuthSession();
+
const totalComments = await prisma.comment.count({
where: {
rootType,
@@ -28,6 +29,17 @@ export async function getPaginatedComments({
},
});
+ const totalReplies = await prisma.comment.count({
+ where: {
+ rootType,
+ parentId: {
+ not: null,
+ },
+ visible: true,
+ ...(rootType === 'CHALLENGE' ? { rootChallengeId: rootId } : { rootSolutionId: rootId }),
+ },
+ });
+
const comments = await prisma.comment.findMany({
skip: (page - 1) * PAGESIZE,
take: PAGESIZE,
@@ -71,8 +83,6 @@ export async function getPaginatedComments({
const totalPages = Math.ceil(totalComments / PAGESIZE);
- const totalReplies = comments.reduce((a, c) => a + c._count.replies, 0);
-
return {
totalComments: totalReplies + totalComments,
totalPages,