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