mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 01:31:12 -05:00
feat: Implement database-level sorting for moderation queue
This commit is contained in:
@@ -10,6 +10,7 @@ import type {
|
||||
EntityFilter,
|
||||
StatusFilter,
|
||||
QueueTab,
|
||||
SortConfig,
|
||||
} from '@/types/moderation';
|
||||
|
||||
/**
|
||||
@@ -24,6 +25,7 @@ export interface QueryConfig {
|
||||
isSuperuser: boolean;
|
||||
currentPage: number;
|
||||
pageSize: number;
|
||||
sortConfig?: SortConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,9 +75,23 @@ export function buildSubmissionQuery(
|
||||
item_data,
|
||||
status
|
||||
)
|
||||
`)
|
||||
.order('escalated', { ascending: false })
|
||||
.order('created_at', { ascending: true });
|
||||
`);
|
||||
|
||||
// CRITICAL: Multi-level ordering
|
||||
// Level 1: Always sort by escalated first (descending) - escalated items always appear at top
|
||||
query = query.order('escalated', { ascending: false });
|
||||
|
||||
// Level 2: Apply user-selected sort (if provided)
|
||||
if (config.sortConfig) {
|
||||
query = query.order(config.sortConfig.field, {
|
||||
ascending: config.sortConfig.direction === 'asc'
|
||||
});
|
||||
}
|
||||
|
||||
// Level 3: Tertiary sort by created_at as tiebreaker (if not already primary sort)
|
||||
if (!config.sortConfig || config.sortConfig.field !== 'created_at') {
|
||||
query = query.order('created_at', { ascending: true });
|
||||
}
|
||||
|
||||
// Apply tab-based status filtering
|
||||
if (tab === 'mainQueue') {
|
||||
|
||||
Reference in New Issue
Block a user