mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 18:11:12 -05:00
Fix moderation queue auto-refresh on tab switch
This commit is contained in:
@@ -137,6 +137,7 @@ export function useModerationQueueManager(
|
|||||||
const pauseFetchingRef = useRef(false);
|
const pauseFetchingRef = useRef(false);
|
||||||
const initialFetchCompleteRef = useRef(false);
|
const initialFetchCompleteRef = useRef(false);
|
||||||
const isMountingRef = useRef(true);
|
const isMountingRef = useRef(true);
|
||||||
|
const fetchItemsRef = useRef<((silent?: boolean) => Promise<void>) | null>(null);
|
||||||
|
|
||||||
const FETCH_COOLDOWN_MS = 1000;
|
const FETCH_COOLDOWN_MS = 1000;
|
||||||
|
|
||||||
@@ -428,6 +429,11 @@ export function useModerationQueueManager(
|
|||||||
}
|
}
|
||||||
}, [user, isAdmin, isSuperuser, filters, pagination, profileCache, entityCache, toast]);
|
}, [user, isAdmin, isSuperuser, filters, pagination, profileCache, entityCache, toast]);
|
||||||
|
|
||||||
|
// Store fetchItems in ref to avoid re-creating visibility listener
|
||||||
|
useEffect(() => {
|
||||||
|
fetchItemsRef.current = fetchItems;
|
||||||
|
}, [fetchItems]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show pending new items by merging them into the queue
|
* Show pending new items by merging them into the queue
|
||||||
*/
|
*/
|
||||||
@@ -788,6 +794,12 @@ export function useModerationQueueManager(
|
|||||||
|
|
||||||
// Visibility change handler
|
// Visibility change handler
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// Early return if feature is disabled
|
||||||
|
if (!settings.refreshOnTabVisible) {
|
||||||
|
console.log('⚙️ refreshOnTabVisible is DISABLED - no listener attached');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const handleVisibilityChange = () => {
|
const handleVisibilityChange = () => {
|
||||||
if (document.hidden) {
|
if (document.hidden) {
|
||||||
console.log('📴 Tab hidden - pausing queue updates');
|
console.log('📴 Tab hidden - pausing queue updates');
|
||||||
@@ -796,16 +808,21 @@ export function useModerationQueueManager(
|
|||||||
console.log('📱 Tab visible - resuming queue updates');
|
console.log('📱 Tab visible - resuming queue updates');
|
||||||
pauseFetchingRef.current = false;
|
pauseFetchingRef.current = false;
|
||||||
|
|
||||||
if (settings.refreshOnTabVisible && initialFetchCompleteRef.current && !isMountingRef.current) {
|
if (initialFetchCompleteRef.current && !isMountingRef.current && fetchItemsRef.current) {
|
||||||
console.log('🔄 Tab became visible - triggering refresh');
|
console.log('🔄 Tab became visible - triggering refresh (setting enabled)');
|
||||||
fetchItems(true);
|
fetchItemsRef.current(true);
|
||||||
|
} else {
|
||||||
|
console.log('⏭️ Tab became visible - skipping refresh (initial fetch not complete or mounting)');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
document.addEventListener('visibilitychange', handleVisibilityChange);
|
document.addEventListener('visibilitychange', handleVisibilityChange);
|
||||||
return () => document.removeEventListener('visibilitychange', handleVisibilityChange);
|
return () => {
|
||||||
}, [settings.refreshOnTabVisible, fetchItems]);
|
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
||||||
|
console.log('🧹 Visibility listener removed');
|
||||||
|
};
|
||||||
|
}, [settings.refreshOnTabVisible]);
|
||||||
|
|
||||||
// Initialize realtime subscriptions
|
// Initialize realtime subscriptions
|
||||||
useRealtimeSubscriptions({
|
useRealtimeSubscriptions({
|
||||||
|
|||||||
Reference in New Issue
Block a user