Implement Phase 6: Lock Management

This commit is contained in:
gpt-engineer-app[bot]
2025-10-12 22:57:37 +00:00
parent 7e6b99a68b
commit 0d0e352a1e
6 changed files with 281 additions and 70 deletions

View File

@@ -397,6 +397,34 @@ export const useModerationQueue = () => {
}
}, [user, currentLock, toast, fetchStats]);
// Check if submission is locked by current user
const isLockedByMe = useCallback((submissionId: string): boolean => {
return currentLock?.submissionId === submissionId;
}, [currentLock]);
// Check if submission is locked by another moderator
const isLockedByOther = useCallback((submissionId: string, assignedTo: string | null, lockedUntil: string | null): boolean => {
if (!assignedTo || !lockedUntil) return false;
if (user?.id === assignedTo) return false; // It's our lock
return new Date(lockedUntil) > new Date(); // Lock is still active
}, [user]);
// Get lock progress percentage (0-100)
const getLockProgress = useCallback((): number => {
const timeLeft = getTimeRemaining();
if (timeLeft === null) return 0;
const totalTime = 15 * 60 * 1000; // 15 minutes in ms
return Math.max(0, Math.min(100, (timeLeft / totalTime) * 100));
}, [getTimeRemaining]);
// Auto-release lock after moderation action
const releaseAfterAction = useCallback(async (submissionId: string, action: 'approved' | 'rejected'): Promise<void> => {
if (currentLock?.submissionId === submissionId) {
await releaseLock(submissionId);
console.log(`🔓 Auto-released lock after ${action} action`);
}
}, [currentLock, releaseLock]);
return {
currentLock,
queueStats,
@@ -409,6 +437,11 @@ export const useModerationQueue = () => {
escalateSubmission,
reassignSubmission,
refreshStats: fetchStats,
// New helpers
isLockedByMe,
isLockedByOther,
getLockProgress,
releaseAfterAction,
};
};