From ef913fcc8d9c6d0cd4e553a93835a5f63e4cd4e2 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Mon, 13 Oct 2025 01:37:19 +0000 Subject: [PATCH] Fix count query for sorting --- .../moderation/useModerationQueueManager.ts | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/hooks/moderation/useModerationQueueManager.ts b/src/hooks/moderation/useModerationQueueManager.ts index 13edaa48..dc4fed1d 100644 --- a/src/hooks/moderation/useModerationQueueManager.ts +++ b/src/hooks/moderation/useModerationQueueManager.ts @@ -279,12 +279,44 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig): ); } - // Get total count - const { count } = await supabase + // Get total count - rebuild query with same filters + let countQuery = supabase .from("content_submissions") - .select("*", { count: "exact", head: true }) - .match(submissionsQuery as any); + .select("*", { count: "exact", head: true }); + // Apply the exact same filters as the main query + if (tab === "mainQueue") { + if (statusFilter === "all") { + countQuery = countQuery.in("status", ["pending", "flagged", "partially_approved"]); + } else if (statusFilter === "pending") { + countQuery = countQuery.in("status", ["pending", "partially_approved"]); + } else { + countQuery = countQuery.eq("status", statusFilter); + } + } else { + if (statusFilter === "all") { + countQuery = countQuery.in("status", ["approved", "rejected"]); + } else { + countQuery = countQuery.eq("status", statusFilter); + } + } + + // Apply entity type filter + if (entityFilter === "photos") { + countQuery = countQuery.eq("submission_type", "photo"); + } else if (entityFilter === "submissions") { + countQuery = countQuery.neq("submission_type", "photo"); + } + + // Apply access control + if (!isAdmin && !isSuperuser) { + const now = new Date().toISOString(); + countQuery = countQuery.or( + `assigned_to.is.null,locked_until.lt.${now},assigned_to.eq.${user.id}`, + ); + } + + const { count } = await countQuery; pagination.setTotalCount(count || 0); // Apply pagination