From 099157bf7445519be4d2b49db4634d447b78b80c Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 19 Feb 2026 09:33:14 +0100 Subject: [PATCH] Fix project status badges to show counts across all pages The status summary badges (Eligible, Rejected, Assigned, etc.) were computed from only the current page's projects. Now uses a groupBy query on the same filters to return statusCounts for all matching projects across all pages. Co-Authored-By: Claude Opus 4.6 --- src/app/(admin)/admin/projects/page.tsx | 8 +------- src/server/routers/project.ts | 14 +++++++++++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/app/(admin)/admin/projects/page.tsx b/src/app/(admin)/admin/projects/page.tsx index 66f0550..778fc9d 100644 --- a/src/app/(admin)/admin/projects/page.tsx +++ b/src/app/(admin)/admin/projects/page.tsx @@ -711,13 +711,7 @@ export default function ProjectsPage() { {data && data.projects.length > 0 && (
- {Object.entries( - data.projects.reduce>((acc, p) => { - const s = p.status ?? 'SUBMITTED' - acc[s] = (acc[s] || 0) + 1 - return acc - }, {}) - ) + {Object.entries(data.statusCounts ?? {}) .sort(([a], [b]) => { const order = ['SUBMITTED', 'ELIGIBLE', 'ASSIGNED', 'SEMIFINALIST', 'FINALIST', 'WINNER', 'REJECTED', 'WITHDRAWN'] return order.indexOf(a) - order.indexOf(b) diff --git a/src/server/routers/project.ts b/src/server/routers/project.ts index 3ab4bab..d085b00 100644 --- a/src/server/routers/project.ts +++ b/src/server/routers/project.ts @@ -140,7 +140,7 @@ export const projectRouter = router({ } } - const [projects, total] = await Promise.all([ + const [projects, total, statusGroups] = await Promise.all([ ctx.prisma.project.findMany({ where, skip, @@ -152,14 +152,26 @@ export const projectRouter = router({ }, }), ctx.prisma.project.count({ where }), + ctx.prisma.project.groupBy({ + by: ['status'], + where, + _count: true, + }), ]) + // Build status counts from groupBy (across all pages) + const statusCounts: Record = {} + for (const g of statusGroups) { + statusCounts[g.status] = g._count + } + return { projects, total, page, perPage, totalPages: Math.ceil(total / perPage), + statusCounts, } }),