mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 14:31:12 -05:00
Fix: Implement comprehensive sorting fixes
This commit is contained in:
@@ -255,19 +255,33 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
||||
uiField: sort.field,
|
||||
dbColumn: sortColumn,
|
||||
direction: sort.direction,
|
||||
ascending: sortAscending
|
||||
ascending: sortAscending,
|
||||
sortObjectRef: sort,
|
||||
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;
|
||||
}
|
||||
})(),
|
||||
});
|
||||
|
||||
submissionsQuery = submissionsQuery.order(sortColumn, { ascending: sortAscending });
|
||||
|
||||
// Secondary sort by created_at for consistency when primary sort has ties
|
||||
if (sortColumn !== 'created_at') {
|
||||
submissionsQuery = submissionsQuery.order('created_at', { ascending: true });
|
||||
// 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');
|
||||
}
|
||||
|
||||
// Validate sort was applied
|
||||
if (!sortColumn) {
|
||||
console.error('❌ [Query] Sort column is undefined! Using fallback.');
|
||||
// Secondary sort by created_at for consistency when primary sort has ties
|
||||
if (sortColumn !== 'created_at') {
|
||||
submissionsQuery = submissionsQuery.order('created_at', { ascending: true });
|
||||
}
|
||||
|
||||
@@ -939,8 +953,11 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
||||
// Refetch when sort configuration changes
|
||||
useEffect(() => {
|
||||
console.log('🔄 [Sort Changed]', {
|
||||
field: sort.config.field,
|
||||
direction: sort.config.direction,
|
||||
field: sort.field,
|
||||
direction: sort.direction,
|
||||
configField: sort.config.field,
|
||||
configDirection: sort.config.direction,
|
||||
match: sort.field === sort.config.field && sort.direction === sort.config.direction,
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
|
||||
@@ -956,10 +973,17 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
||||
return;
|
||||
}
|
||||
|
||||
// Trigger refetch with new sort
|
||||
// CRITICAL: Ensure we're using the latest fetchItems
|
||||
if (fetchItemsRef.current) {
|
||||
console.log('✅ Triggering refetch due to sort change');
|
||||
console.log('✅ Triggering refetch due to sort change', {
|
||||
willUseField: sort.field,
|
||||
willUseDirection: sort.direction
|
||||
});
|
||||
|
||||
// Force immediate refetch
|
||||
fetchItemsRef.current(false);
|
||||
} else {
|
||||
console.error('❌ fetchItemsRef.current is null - cannot refetch!');
|
||||
}
|
||||
}, [sort.field, sort.direction]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user