Fix count query for sorting

This commit is contained in:
gpt-engineer-app[bot]
2025-10-13 01:37:19 +00:00
parent 9cf969bb9d
commit ef913fcc8d

View File

@@ -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