mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 09:31:13 -05:00
Fix count query for sorting
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user