Files
thrilltrack-explorer/src/components/moderation/QueueSortControls.tsx
pac7 b56617efcc Enhance moderation queue sorting with visual indicators and logging
Add loading spinners, detailed sort query logging, result preview logging, disable sort controls during loading, and mobile-specific loading text changes. Also, fix type mismatch in QueueSortControls and correct refresh strategy logic.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: ef7037e7-a631-48a2-94d1-9a4b52d7c35a
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7cdf4e95-3f41-4180-b8e3-8ef56d032c0e/ef7037e7-a631-48a2-94d1-9a4b52d7c35a/kq6AhNt
2025-10-13 15:16:16 +00:00

101 lines
3.3 KiB
TypeScript

import { ArrowUp, ArrowDown, Loader2 } from 'lucide-react';
import { Label } from '@/components/ui/label';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { Button } from '@/components/ui/button';
import type { SortConfig, SortField } from '@/types/moderation';
interface QueueSortControlsProps {
sortConfig: SortConfig;
onSortChange: (config: SortConfig) => void;
isMobile: boolean;
isLoading?: boolean;
}
const SORT_FIELD_LABELS: Record<SortField, string> = {
created_at: 'Date Submitted',
submission_type: 'Type',
status: 'Status'
};
export const QueueSortControls = ({
sortConfig,
onSortChange,
isMobile,
isLoading = false
}: QueueSortControlsProps) => {
const handleFieldChange = (value: string) => {
const validFields: SortField[] = ['created_at', 'submission_type', 'status'];
if (!validFields.includes(value as SortField)) {
console.warn('⚠️ [SORT] Invalid sort field:', value);
return;
}
const field = value as SortField;
console.log('🔄 [SORT] Field change:', { from: sortConfig.field, to: field });
onSortChange({ ...sortConfig, field });
};
const handleDirectionToggle = () => {
const newDirection = sortConfig.direction === 'asc' ? 'desc' : 'asc';
console.log('🔄 [SORT] Direction toggle:', { from: sortConfig.direction, to: newDirection });
onSortChange({
...sortConfig,
direction: newDirection
});
};
const DirectionIcon = sortConfig.direction === 'asc' ? ArrowUp : ArrowDown;
return (
<div className={`flex gap-2 ${isMobile ? 'flex-col' : 'items-end'}`}>
<div className={`space-y-2 ${isMobile ? 'w-full' : 'min-w-[160px]'}`}>
<Label className={`font-medium ${isMobile ? 'text-xs' : 'text-sm'} flex items-center gap-2`}>
Sort By
{isLoading && <Loader2 className="w-3 h-3 animate-spin text-primary" />}
</Label>
<Select
value={sortConfig.field}
onValueChange={handleFieldChange}
disabled={isLoading}
>
<SelectTrigger className={isMobile ? "h-10" : ""} disabled={isLoading}>
<SelectValue>
{SORT_FIELD_LABELS[sortConfig.field]}
</SelectValue>
</SelectTrigger>
<SelectContent>
{Object.entries(SORT_FIELD_LABELS).map(([field, label]) => (
<SelectItem key={field} value={field}>
{label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className={isMobile ? "" : "pb-[2px]"}>
<Button
variant="outline"
size={isMobile ? "default" : "icon"}
onClick={handleDirectionToggle}
disabled={isLoading}
className={`flex items-center gap-2 ${isMobile ? 'w-full h-10' : 'h-10 w-10'}`}
title={sortConfig.direction === 'asc' ? 'Ascending' : 'Descending'}
>
{isLoading ? (
<Loader2 className="w-4 h-4 animate-spin" />
) : (
<DirectionIcon className="w-4 h-4" />
)}
{isMobile && (
<span className="capitalize">
{isLoading ? 'Loading...' : `${sortConfig.direction}ending`}
</span>
)}
</Button>
</div>
</div>
);
};