mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 16:31:13 -05:00
Fix: Restore escalated sort order
This commit is contained in:
@@ -253,11 +253,15 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
||||
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,
|
||||
sortObjectRef: sort,
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
|
||||
@@ -273,6 +277,10 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
||||
})(),
|
||||
});
|
||||
|
||||
// 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
|
||||
@@ -281,7 +289,7 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
||||
throw new Error('Supabase query builder is not functioning correctly');
|
||||
}
|
||||
|
||||
// Secondary sort by created_at for consistency when primary sort has ties
|
||||
// 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 });
|
||||
}
|
||||
@@ -387,14 +395,13 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
||||
// VALIDATE: Log first few items to verify sort is working
|
||||
if (submissions && submissions.length > 0) {
|
||||
console.log('[Query] Results returned (first 3 items):', {
|
||||
sortColumn,
|
||||
sortDirection: sortAscending ? 'ASC' : 'DESC',
|
||||
sortLevels: `escalated DESC → ${sortColumn} ${sortAscending ? 'ASC' : 'DESC'}`,
|
||||
items: submissions.slice(0, 3).map(s => ({
|
||||
id: s.id.substring(0, 8),
|
||||
escalated: s.escalated,
|
||||
type: s.submission_type,
|
||||
status: s.status,
|
||||
created: s.created_at,
|
||||
escalated: s.escalated,
|
||||
sortValue: s[sortColumn as keyof typeof s]
|
||||
}))
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user