feat: Implement database-level sorting for moderation queue

This commit is contained in:
gpt-engineer-app[bot]
2025-10-13 13:23:54 +00:00
parent 90ae7d9a41
commit 0af5443c81
8 changed files with 269 additions and 18 deletions

View File

@@ -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') {