mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 08:11:12 -05:00
Fix: Correct moderation queue filtering
This commit is contained in:
@@ -248,53 +248,7 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
||||
`
|
||||
);
|
||||
|
||||
// Apply user-selected sort configuration
|
||||
const sortColumn = getSortColumn(sort.field);
|
||||
const sortAscending = sort.direction === 'asc';
|
||||
|
||||
console.log('[Query] Applying sort:', {
|
||||
sortLevels: [
|
||||
'1. escalated DESC (always first)',
|
||||
`2. ${sortColumn} ${sortAscending ? 'ASC' : 'DESC'} (user selected)`,
|
||||
sortColumn !== 'created_at' ? '3. created_at ASC (tie-breaker)' : null
|
||||
].filter(Boolean),
|
||||
uiField: sort.field,
|
||||
dbColumn: sortColumn,
|
||||
direction: sort.direction,
|
||||
ascending: sortAscending,
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
|
||||
// Log what localStorage has
|
||||
console.log('[Query] Sort config persistence:', {
|
||||
localStorageValue: localStorage.getItem('moderationQueue_sortConfig'),
|
||||
parsedValue: (() => {
|
||||
try {
|
||||
return JSON.parse(localStorage.getItem('moderationQueue_sortConfig') || 'null');
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
})(),
|
||||
});
|
||||
|
||||
// Always prioritize escalated submissions first
|
||||
submissionsQuery = submissionsQuery.order('escalated', { ascending: false });
|
||||
|
||||
// Then apply user-selected sort
|
||||
submissionsQuery = submissionsQuery.order(sortColumn, { ascending: sortAscending });
|
||||
|
||||
// CRITICAL: Verify the query builder chain is working
|
||||
if (!submissionsQuery.order) {
|
||||
console.error('❌ [CRITICAL] Query builder broken - order method not found!');
|
||||
throw new Error('Supabase query builder is not functioning correctly');
|
||||
}
|
||||
|
||||
// Tertiary sort by created_at for consistency (only if not already the user's sort choice)
|
||||
if (sortColumn !== 'created_at') {
|
||||
submissionsQuery = submissionsQuery.order('created_at', { ascending: true });
|
||||
}
|
||||
|
||||
// Apply tab-based status filtering
|
||||
// Apply tab-based status filtering FIRST
|
||||
const tab = filters.activeTab;
|
||||
const statusFilter = filters.debouncedStatusFilter;
|
||||
const entityFilter = filters.debouncedEntityFilter;
|
||||
@@ -322,7 +276,7 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
||||
submissionsQuery = submissionsQuery.neq("submission_type", "photo");
|
||||
}
|
||||
|
||||
// Apply access control
|
||||
// Apply access control (must be AFTER status/entity filters to work as AND)
|
||||
if (!isAdmin && !isSuperuser) {
|
||||
const now = new Date().toISOString();
|
||||
submissionsQuery = submissionsQuery.or(
|
||||
@@ -330,12 +284,40 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
||||
);
|
||||
}
|
||||
|
||||
// Get total count for pagination (rebuild query with same filters)
|
||||
// Apply user-selected sort configuration
|
||||
const sortColumn = getSortColumn(sort.field);
|
||||
const sortAscending = sort.direction === 'asc';
|
||||
|
||||
console.log('[Query] Applying sort:', {
|
||||
sortLevels: [
|
||||
'1. escalated DESC (always first)',
|
||||
`2. ${sortColumn} ${sortAscending ? 'ASC' : 'DESC'} (user selected)`,
|
||||
sortColumn !== 'created_at' ? '3. created_at ASC (tie-breaker)' : null
|
||||
].filter(Boolean),
|
||||
uiField: sort.field,
|
||||
dbColumn: sortColumn,
|
||||
direction: sort.direction,
|
||||
ascending: sortAscending,
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
|
||||
// Always prioritize escalated submissions first
|
||||
submissionsQuery = submissionsQuery.order('escalated', { ascending: false });
|
||||
|
||||
// Then apply user-selected sort
|
||||
submissionsQuery = submissionsQuery.order(sortColumn, { ascending: sortAscending });
|
||||
|
||||
// Tertiary sort by created_at for consistency (only if not already the user's sort choice)
|
||||
if (sortColumn !== 'created_at') {
|
||||
submissionsQuery = submissionsQuery.order('created_at', { ascending: true });
|
||||
}
|
||||
|
||||
// Get total count for pagination (rebuild query with same filters in SAME ORDER)
|
||||
let countQuery = supabase
|
||||
.from("content_submissions")
|
||||
.select("*", { count: "exact", head: true });
|
||||
|
||||
// Apply same filters as main query
|
||||
// Apply same filters as main query - status filter FIRST
|
||||
if (tab === "mainQueue") {
|
||||
if (statusFilter === "all") {
|
||||
countQuery = countQuery.in("status", ["pending", "flagged", "partially_approved"]);
|
||||
@@ -352,12 +334,14 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
||||
}
|
||||
}
|
||||
|
||||
// Entity type filter
|
||||
if (entityFilter === "photos") {
|
||||
countQuery = countQuery.eq("submission_type", "photo");
|
||||
} else if (entityFilter === "submissions") {
|
||||
countQuery = countQuery.neq("submission_type", "photo");
|
||||
}
|
||||
|
||||
// Access control (AFTER status/entity filters)
|
||||
if (!isAdmin && !isSuperuser) {
|
||||
const now = new Date().toISOString();
|
||||
countQuery = countQuery.or(
|
||||
|
||||
Reference in New Issue
Block a user