mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 15:11:12 -05:00
Fix sorting logic in moderation queue
This commit is contained in:
@@ -238,25 +238,26 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
|||||||
item_data,
|
item_data,
|
||||||
status
|
status
|
||||||
)
|
)
|
||||||
`,
|
`
|
||||||
)
|
);
|
||||||
// Apply user-selected sort configuration
|
|
||||||
const sortColumn = getSortColumn(sort.field);
|
|
||||||
const sortAscending = sort.direction === 'asc';
|
|
||||||
|
|
||||||
console.log('[Query] Applying sort:', {
|
// Apply user-selected sort configuration
|
||||||
uiField: sort.field,
|
const sortColumn = getSortColumn(sort.field);
|
||||||
dbColumn: sortColumn,
|
const sortAscending = sort.direction === 'asc';
|
||||||
direction: sort.direction,
|
|
||||||
ascending: sortAscending
|
|
||||||
});
|
|
||||||
|
|
||||||
submissionsQuery = submissionsQuery.order(sortColumn, { ascending: sortAscending });
|
console.log('[Query] Applying sort:', {
|
||||||
|
uiField: sort.field,
|
||||||
|
dbColumn: sortColumn,
|
||||||
|
direction: sort.direction,
|
||||||
|
ascending: sortAscending
|
||||||
|
});
|
||||||
|
|
||||||
// Secondary sort by created_at for consistency when primary sort has ties
|
submissionsQuery = submissionsQuery.order(sortColumn, { ascending: sortAscending });
|
||||||
if (sortColumn !== 'created_at') {
|
|
||||||
submissionsQuery = submissionsQuery.order('created_at', { ascending: true });
|
// Secondary sort by created_at for consistency when primary sort has ties
|
||||||
}
|
if (sortColumn !== 'created_at') {
|
||||||
|
submissionsQuery = submissionsQuery.order('created_at', { ascending: true });
|
||||||
|
}
|
||||||
|
|
||||||
// Apply tab-based status filtering
|
// Apply tab-based status filtering
|
||||||
const tab = filters.activeTab;
|
const tab = filters.activeTab;
|
||||||
@@ -307,6 +308,21 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
|||||||
const endIndex = pagination.endIndex;
|
const endIndex = pagination.endIndex;
|
||||||
submissionsQuery = submissionsQuery.range(startIndex, endIndex);
|
submissionsQuery = submissionsQuery.range(startIndex, endIndex);
|
||||||
|
|
||||||
|
// Log the final query for debugging
|
||||||
|
console.log('[Query] Final query about to execute:', {
|
||||||
|
sortApplied: sortColumn,
|
||||||
|
sortDirection: sortAscending ? 'ASC' : 'DESC',
|
||||||
|
filtersApplied: {
|
||||||
|
tab: filters.activeTab,
|
||||||
|
status: filters.debouncedStatusFilter,
|
||||||
|
entity: filters.debouncedEntityFilter,
|
||||||
|
},
|
||||||
|
pagination: {
|
||||||
|
startIndex,
|
||||||
|
endIndex
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const { data: submissions, error: submissionsError } = await submissionsQuery;
|
const { data: submissions, error: submissionsError } = await submissionsQuery;
|
||||||
|
|
||||||
if (submissionsError) throw submissionsError;
|
if (submissionsError) throw submissionsError;
|
||||||
@@ -485,7 +501,7 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
|||||||
setLoadingState("ready");
|
setLoadingState("ready");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[user, isAdmin, isSuperuser, filters, pagination, profileCache, entityCache, toast],
|
[user, isAdmin, isSuperuser, filters, pagination, profileCache, entityCache, toast, sort],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Store fetchItems in ref to avoid re-creating visibility listener
|
// Store fetchItems in ref to avoid re-creating visibility listener
|
||||||
|
|||||||
Reference in New Issue
Block a user