mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 23:11:13 -05:00
feat: Implement all 7 phases
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user