diff --git a/src/components/timeline.jsx b/src/components/timeline.jsx index 9d7984ba..d5ad0bd4 100644 --- a/src/components/timeline.jsx +++ b/src/components/timeline.jsx @@ -1,3 +1,4 @@ +import { useIdle } from '@uidotdev/usehooks'; import { useCallback, useEffect, useRef, useState } from 'preact/hooks'; import { useHotkeys } from 'react-hotkeys-hook'; import { InView } from 'react-intersection-observer'; @@ -205,13 +206,21 @@ function Timeline({ }, [nearReachEnd, showMore]); const isHovering = useRef(false); + const idle = useIdle(5000); + console.debug('🧘‍♀️ IDLE', idle); const loadOrCheckUpdates = useCallback( async ({ disableHoverCheck = false } = {}) => { - console.log('✨ Load or check updates', snapStates.settings.autoRefresh); + console.log('✨ Load or check updates', { + autoRefresh: snapStates.settings.autoRefresh, + scrollTop: scrollableRef.current.scrollTop, + disableHoverCheck, + idle, + inBackground: inBackground(), + }); if ( snapStates.settings.autoRefresh && scrollableRef.current.scrollTop === 0 && - (disableHoverCheck || !isHovering.current) && + (disableHoverCheck || idle) && !inBackground() ) { console.log('✨ Load updates', snapStates.settings.autoRefresh); @@ -225,7 +234,7 @@ function Timeline({ } } }, - [id, loadItems, checkForUpdates, snapStates.settings.autoRefresh], + [id, idle, loadItems, checkForUpdates, snapStates.settings.autoRefresh], ); const lastHiddenTime = useRef(); diff --git a/src/pages/notifications.jsx b/src/pages/notifications.jsx index cb2af4ec..03490828 100644 --- a/src/pages/notifications.jsx +++ b/src/pages/notifications.jsx @@ -1,5 +1,6 @@ import './notifications.css'; +import { useIdle } from '@uidotdev/usehooks'; import { memo } from 'preact/compat'; import { useCallback, useEffect, useRef, useState } from 'preact/hooks'; import { useSnapshot } from 'valtio'; @@ -146,6 +147,8 @@ function Notifications() { }, [nearReachEnd, showMore]); const isHovering = useRef(false); + const idle = useIdle(5000); + console.debug('🧘‍♀️ IDLE', idle); const loadUpdates = useCallback(() => { console.log('✨ Load updates', { autoRefresh: snapStates.settings.autoRefresh, @@ -158,7 +161,7 @@ function Notifications() { if ( snapStates.settings.autoRefresh && scrollableRef.current?.scrollTop === 0 && - !isHovering.current && + (!isHovering.current || idle) && !inBackground() && snapStates.notificationsShowNew && uiState !== 'loading' @@ -166,6 +169,7 @@ function Notifications() { loadNotifications(true); } }, [ + idle, snapStates.notificationsShowNew, snapStates.settings.autoRefresh, uiState,