Fix moderation queue claim logic

This commit is contained in:
gpt-engineer-app[bot]
2025-11-05 16:37:54 +00:00
parent 7c35f2932b
commit 80d823a1b9
2 changed files with 78 additions and 9 deletions

View File

@@ -187,6 +187,26 @@ export const useModerationQueue = (config?: UseModerationQueueConfig) => {
// Only restore if lock hasn't expired (race condition check)
if (data.locked_until && expiresAt > new Date()) {
const timeRemaining = expiresAt.getTime() - new Date().getTime();
const minTimeMs = 60 * 1000; // 60 seconds minimum
if (timeRemaining < minTimeMs) {
// Lock expires too soon - auto-release it
logger.info('Lock expired or expiring soon, auto-releasing', {
submissionId: data.id,
timeRemainingSeconds: Math.floor(timeRemaining / 1000),
});
// Release the stale lock
await supabase.rpc('release_submission_lock', {
submission_id: data.id,
moderator_id: user.id,
});
return; // Don't restore
}
// Lock has sufficient time - restore it
setCurrentLock({
submissionId: data.id,
expiresAt,
@@ -198,6 +218,7 @@ export const useModerationQueue = (config?: UseModerationQueueConfig) => {
logger.info('Lock state restored from database', {
submissionId: data.id,
expiresAt: expiresAt.toISOString(),
timeRemainingSeconds: Math.floor(timeRemaining / 1000),
});
}
}
@@ -399,6 +420,15 @@ export const useModerationQueue = (config?: UseModerationQueueConfig) => {
return false;
}
// Check if trying to claim same submission user already has locked
if (currentLock && currentLock.submissionId === submissionId) {
toast({
title: 'Already Claimed',
description: 'You already have this submission claimed. Review it below.',
});
return true; // Return success, don't re-claim
}
// Check if user already has an active lock on a different submission
if (currentLock && currentLock.submissionId !== submissionId) {
toast({