mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 04:51:13 -05:00
Fix queue refresh on lock state change
This commit is contained in:
@@ -81,6 +81,7 @@ export const QueueItem = memo(({
|
|||||||
onInteractionBlur
|
onInteractionBlur
|
||||||
}: QueueItemProps) => {
|
}: QueueItemProps) => {
|
||||||
const [validationResult, setValidationResult] = useState<ValidationResult | null>(null);
|
const [validationResult, setValidationResult] = useState<ValidationResult | null>(null);
|
||||||
|
const [isClaiming, setIsClaiming] = useState(false);
|
||||||
|
|
||||||
// Fetch relational photo data for photo submissions
|
// Fetch relational photo data for photo submissions
|
||||||
const { photos: photoItems, loading: photosLoading } = usePhotoSubmissionItems(
|
const { photos: photoItems, loading: photosLoading } = usePhotoSubmissionItems(
|
||||||
@@ -96,6 +97,12 @@ export const QueueItem = memo(({
|
|||||||
setValidationResult(result);
|
setValidationResult(result);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const handleClaim = useCallback(async () => {
|
||||||
|
setIsClaiming(true);
|
||||||
|
await onClaimSubmission(item.id);
|
||||||
|
setIsClaiming(false);
|
||||||
|
}, [onClaimSubmission, item.id]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
key={item.id}
|
key={item.id}
|
||||||
@@ -298,7 +305,14 @@ export const QueueItem = memo(({
|
|||||||
<div className="text-sm text-muted-foreground">Loading photos...</div>
|
<div className="text-sm text-muted-foreground">Loading photos...</div>
|
||||||
) : photoItems.length > 0 ? (
|
) : photoItems.length > 0 ? (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<div className="text-sm font-medium">Photos ({photoItems.length}):</div>
|
<div className="text-sm font-medium flex items-center justify-between">
|
||||||
|
<span>Photos ({photoItems.length}):</span>
|
||||||
|
{import.meta.env.DEV && photoItems[0] && (
|
||||||
|
<span className="text-xs text-muted-foreground">
|
||||||
|
URL: {photoItems[0].cloudflare_image_url?.slice(0, 30)}...
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<PhotoGrid
|
<PhotoGrid
|
||||||
photos={photoItems.map(photo => ({
|
photos={photoItems.map(photo => ({
|
||||||
id: photo.id,
|
id: photo.id,
|
||||||
@@ -312,9 +326,13 @@ export const QueueItem = memo(({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="text-sm text-muted-foreground">
|
<Alert variant="destructive" className="mt-4">
|
||||||
No photos found in submission
|
<AlertTriangle className="h-4 w-4" />
|
||||||
</div>
|
<AlertTitle>No Photos Found</AlertTitle>
|
||||||
|
<AlertDescription>
|
||||||
|
This photo submission has no photos attached. This may be a data integrity issue.
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Context Information */}
|
{/* Context Information */}
|
||||||
@@ -356,13 +374,22 @@ export const QueueItem = memo(({
|
|||||||
<div className="flex items-center justify-between mt-2">
|
<div className="flex items-center justify-between mt-2">
|
||||||
<span className="text-sm">Claim this submission to lock it for 15 minutes while you review</span>
|
<span className="text-sm">Claim this submission to lock it for 15 minutes while you review</span>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => onClaimSubmission(item.id)}
|
onClick={handleClaim}
|
||||||
disabled={queueIsLoading}
|
disabled={queueIsLoading || isClaiming}
|
||||||
size="sm"
|
size="sm"
|
||||||
className="ml-4"
|
className="ml-4"
|
||||||
>
|
>
|
||||||
|
{isClaiming ? (
|
||||||
|
<>
|
||||||
|
<RefreshCw className="w-4 h-4 mr-2 animate-spin" />
|
||||||
|
Claiming...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
<Lock className="w-4 h-4 mr-2" />
|
<Lock className="w-4 h-4 mr-2" />
|
||||||
Claim Submission
|
Claim Submission
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</AlertDescription>
|
</AlertDescription>
|
||||||
|
|||||||
@@ -111,7 +111,12 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const queue = useModerationQueue();
|
const queue = useModerationQueue({
|
||||||
|
onLockStateChange: () => {
|
||||||
|
logger.log('🔄 Lock state changed, invalidating queue cache');
|
||||||
|
queueQuery.invalidate();
|
||||||
|
}
|
||||||
|
});
|
||||||
const entityCache = useEntityCache();
|
const entityCache = useEntityCache();
|
||||||
const profileCache = useProfileCache();
|
const profileCache = useProfileCache();
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,12 @@ interface QueueStats {
|
|||||||
avgWaitHours: number;
|
avgWaitHours: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useModerationQueue = () => {
|
interface UseModerationQueueConfig {
|
||||||
|
onLockStateChange?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useModerationQueue = (config?: UseModerationQueueConfig) => {
|
||||||
|
const { onLockStateChange } = config || {};
|
||||||
const [currentLock, setCurrentLock] = useState<LockState | null>(null);
|
const [currentLock, setCurrentLock] = useState<LockState | null>(null);
|
||||||
const [queueStats, setQueueStats] = useState<QueueStats | null>(null);
|
const [queueStats, setQueueStats] = useState<QueueStats | null>(null);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
@@ -158,6 +163,11 @@ export const useModerationQueue = () => {
|
|||||||
description: `${claimed.submission_type} submission (waiting ${formatInterval(claimed.waiting_time)})`,
|
description: `${claimed.submission_type} submission (waiting ${formatInterval(claimed.waiting_time)})`,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Trigger refresh callback
|
||||||
|
if (onLockStateChange) {
|
||||||
|
onLockStateChange();
|
||||||
|
}
|
||||||
|
|
||||||
return claimed.submission_id;
|
return claimed.submission_id;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('Error claiming submission:', error);
|
console.error('Error claiming submission:', error);
|
||||||
@@ -239,6 +249,12 @@ export const useModerationQueue = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fetchStats();
|
fetchStats();
|
||||||
|
|
||||||
|
// Trigger refresh callback
|
||||||
|
if (onLockStateChange) {
|
||||||
|
onLockStateChange();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,6 +349,11 @@ export const useModerationQueue = () => {
|
|||||||
description: 'You now have 15 minutes to review this submission',
|
description: 'You now have 15 minutes to review this submission',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Trigger refresh callback
|
||||||
|
if (onLockStateChange) {
|
||||||
|
onLockStateChange();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('Error claiming submission:', error);
|
console.error('Error claiming submission:', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user