feat: Implement all 7 phases

This commit is contained in:
gpt-engineer-app[bot]
2025-11-02 21:00:22 +00:00
parent bccaebc6d6
commit f3c898dfc1
12 changed files with 1236 additions and 42 deletions

View File

@@ -87,8 +87,11 @@ export const useModerationQueue = (config?: UseModerationQueueConfig) => {
}
}, [user]);
// Start countdown timer for lock expiry
// Start countdown timer for lock expiry with improved memory leak prevention
const startLockTimer = useCallback((expiresAt: Date) => {
// Track if component is still mounted
let isMounted = true;
// Clear any existing timer first to prevent leaks
if (lockTimerRef.current) {
clearInterval(lockTimerRef.current);
@@ -96,6 +99,15 @@ export const useModerationQueue = (config?: UseModerationQueueConfig) => {
}
lockTimerRef.current = setInterval(() => {
// Prevent timer execution if component unmounted
if (!isMounted) {
if (lockTimerRef.current) {
clearInterval(lockTimerRef.current);
lockTimerRef.current = null;
}
return;
}
const now = new Date();
const timeLeft = expiresAt.getTime() - now.getTime();
@@ -119,7 +131,16 @@ export const useModerationQueue = (config?: UseModerationQueueConfig) => {
}
}
}, 1000);
}, [toast, onLockStateChange]); // Add dependencies to avoid stale closures
// Return cleanup function
return () => {
isMounted = false;
if (lockTimerRef.current) {
clearInterval(lockTimerRef.current);
lockTimerRef.current = null;
}
};
}, [toast, onLockStateChange]);
// Clean up timer on unmount
useEffect(() => {