mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 12:31:13 -05:00
Fix moderation queue refresh on tab switch
This commit is contained in:
@@ -130,6 +130,7 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
||||
const isMountingRef = useRef(true);
|
||||
const initialFetchCompleteRef = useRef(false);
|
||||
const FETCH_COOLDOWN_MS = 1000;
|
||||
const isPageVisible = useRef(true);
|
||||
|
||||
// Pagination state
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
@@ -212,6 +213,21 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
||||
}
|
||||
}, [loadingState, items.length, hasRenderedOnce]);
|
||||
|
||||
// Track page visibility to prevent tab-switch refreshes
|
||||
useEffect(() => {
|
||||
const handleVisibilityChange = () => {
|
||||
const wasHidden = !isPageVisible.current;
|
||||
isPageVisible.current = !document.hidden;
|
||||
|
||||
if (wasHidden && isPageVisible.current) {
|
||||
console.log('📄 Page became visible - NOT auto-refreshing queue');
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('visibilitychange', handleVisibilityChange);
|
||||
return () => document.removeEventListener('visibilitychange', handleVisibilityChange);
|
||||
}, []);
|
||||
|
||||
const fetchItems = useCallback(async (entityFilter: EntityFilter = 'all', statusFilter: StatusFilter = 'pending', silent = false, tab: QueueTab = 'mainQueue') => {
|
||||
if (!userRef.current) {
|
||||
return;
|
||||
@@ -223,6 +239,12 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip fetch if triggered during tab visibility change (unless manual refresh)
|
||||
if (!silent && !isPageVisible.current) {
|
||||
console.log('👁️ Skipping fetch while page is hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
// Cooldown check - prevent rapid-fire calls
|
||||
const now = Date.now();
|
||||
const timeSinceLastFetch = now - lastFetchTimeRef.current;
|
||||
|
||||
Reference in New Issue
Block a user