mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 05:11:14 -05:00
Fix count query for sorting
This commit is contained in:
@@ -279,12 +279,44 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get total count
|
// Get total count - rebuild query with same filters
|
||||||
const { count } = await supabase
|
let countQuery = supabase
|
||||||
.from("content_submissions")
|
.from("content_submissions")
|
||||||
.select("*", { count: "exact", head: true })
|
.select("*", { count: "exact", head: true });
|
||||||
.match(submissionsQuery as any);
|
|
||||||
|
|
||||||
|
// 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);
|
pagination.setTotalCount(count || 0);
|
||||||
|
|
||||||
// Apply pagination
|
// Apply pagination
|
||||||
|
|||||||
Reference in New Issue
Block a user