mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 14:11:12 -05:00
feat: Implement complete queue system
This commit is contained in:
@@ -266,6 +266,90 @@ export const useModerationQueue = () => {
|
||||
return Math.max(0, currentLock.expiresAt.getTime() - Date.now());
|
||||
}, [currentLock]);
|
||||
|
||||
// Escalate submission
|
||||
const escalateSubmission = useCallback(async (submissionId: string, reason: string): Promise<boolean> => {
|
||||
if (!user?.id) return false;
|
||||
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const { error } = await supabase
|
||||
.from('content_submissions')
|
||||
.update({
|
||||
escalated: true,
|
||||
escalated_at: new Date().toISOString(),
|
||||
escalated_by: user.id,
|
||||
escalation_reason: reason,
|
||||
priority: 10, // Max priority
|
||||
})
|
||||
.eq('id', submissionId);
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
toast({
|
||||
title: 'Submission Escalated',
|
||||
description: 'This submission has been marked as high priority',
|
||||
});
|
||||
|
||||
fetchStats();
|
||||
return true;
|
||||
} catch (error: any) {
|
||||
console.error('Error escalating submission:', error);
|
||||
toast({
|
||||
title: 'Error',
|
||||
description: error.message || 'Failed to escalate submission',
|
||||
variant: 'destructive',
|
||||
});
|
||||
return false;
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, [user, toast, fetchStats]);
|
||||
|
||||
// Reassign submission
|
||||
const reassignSubmission = useCallback(async (submissionId: string, newModeratorId: string): Promise<boolean> => {
|
||||
if (!user?.id) return false;
|
||||
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const { error } = await supabase
|
||||
.from('content_submissions')
|
||||
.update({
|
||||
assigned_to: newModeratorId,
|
||||
assigned_at: new Date().toISOString(),
|
||||
locked_until: new Date(Date.now() + 15 * 60 * 1000).toISOString(),
|
||||
})
|
||||
.eq('id', submissionId);
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
// If this was our lock, clear it
|
||||
if (currentLock?.submissionId === submissionId) {
|
||||
setCurrentLock(null);
|
||||
if (lockTimerRef.current) {
|
||||
clearInterval(lockTimerRef.current);
|
||||
}
|
||||
}
|
||||
|
||||
toast({
|
||||
title: 'Submission Reassigned',
|
||||
description: 'The submission has been assigned to another moderator',
|
||||
});
|
||||
|
||||
fetchStats();
|
||||
return true;
|
||||
} catch (error: any) {
|
||||
console.error('Error reassigning submission:', error);
|
||||
toast({
|
||||
title: 'Error',
|
||||
description: error.message || 'Failed to reassign submission',
|
||||
variant: 'destructive',
|
||||
});
|
||||
return false;
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, [user, currentLock, toast, fetchStats]);
|
||||
|
||||
return {
|
||||
currentLock,
|
||||
queueStats,
|
||||
@@ -274,6 +358,8 @@ export const useModerationQueue = () => {
|
||||
extendLock,
|
||||
releaseLock,
|
||||
getTimeRemaining,
|
||||
escalateSubmission,
|
||||
reassignSubmission,
|
||||
refreshStats: fetchStats,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user