mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 17:31:12 -05:00
Fix sorting mechanism
This commit is contained in:
@@ -163,6 +163,12 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
||||
*/
|
||||
const fetchItems = useCallback(
|
||||
async (silent = false) => {
|
||||
console.log('🔄 [fetchItems RECREATED]', {
|
||||
sortField: sort.field,
|
||||
sortDirection: sort.direction,
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
|
||||
if (!user) return;
|
||||
|
||||
// Get caller info
|
||||
@@ -259,6 +265,12 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
||||
submissionsQuery = submissionsQuery.order('created_at', { ascending: true });
|
||||
}
|
||||
|
||||
// Validate sort was applied
|
||||
if (!sortColumn) {
|
||||
console.error('❌ [Query] Sort column is undefined! Using fallback.');
|
||||
submissionsQuery = submissionsQuery.order('created_at', { ascending: true });
|
||||
}
|
||||
|
||||
// Apply tab-based status filtering
|
||||
const tab = filters.activeTab;
|
||||
const statusFilter = filters.debouncedStatusFilter;
|
||||
@@ -501,7 +513,7 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
||||
setLoadingState("ready");
|
||||
}
|
||||
},
|
||||
[user, isAdmin, isSuperuser, filters, pagination, profileCache, entityCache, toast, sort],
|
||||
[user, isAdmin, isSuperuser, filters, pagination, profileCache, entityCache, toast, sort.field, sort.direction],
|
||||
);
|
||||
|
||||
// Store fetchItems in ref to avoid re-creating visibility listener
|
||||
@@ -949,7 +961,7 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
||||
console.log('✅ Triggering refetch due to sort change');
|
||||
fetchItemsRef.current(false);
|
||||
}
|
||||
}, [sort.config.field, sort.config.direction]);
|
||||
}, [sort.field, sort.direction]);
|
||||
|
||||
// Initialize realtime subscriptions
|
||||
useRealtimeSubscriptions({
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Manages sort configuration for the moderation queue with persistence.
|
||||
*/
|
||||
|
||||
import { useState, useCallback, useEffect } from 'react';
|
||||
import { useState, useCallback, useEffect, useMemo } from 'react';
|
||||
import type { SortConfig, SortField, SortDirection } from '@/types/moderation';
|
||||
import {
|
||||
getDefaultSortConfig,
|
||||
@@ -131,7 +131,7 @@ export function useModerationSort(config: ModerationSortConfig = {}): Moderation
|
||||
// Check if using default config
|
||||
const isDefault = isDefaultSortConfig(sortConfig);
|
||||
|
||||
return {
|
||||
return useMemo(() => ({
|
||||
config: sortConfig,
|
||||
field: sortConfig.field,
|
||||
direction: sortConfig.direction,
|
||||
@@ -141,5 +141,5 @@ export function useModerationSort(config: ModerationSortConfig = {}): Moderation
|
||||
setConfig,
|
||||
reset,
|
||||
isDefault,
|
||||
};
|
||||
}), [sortConfig, setField, setDirection, toggleSortDirection, setConfig, reset, isDefault]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user