this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Try useIdle

+17 -4
+12 -3
src/components/timeline.jsx
··· 1 + import { useIdle } from '@uidotdev/usehooks'; 1 2 import { useCallback, useEffect, useRef, useState } from 'preact/hooks'; 2 3 import { useHotkeys } from 'react-hotkeys-hook'; 3 4 import { InView } from 'react-intersection-observer'; ··· 205 206 }, [nearReachEnd, showMore]); 206 207 207 208 const isHovering = useRef(false); 209 + const idle = useIdle(5000); 210 + console.debug('🧘‍♀️ IDLE', idle); 208 211 const loadOrCheckUpdates = useCallback( 209 212 async ({ disableHoverCheck = false } = {}) => { 210 - console.log('✨ Load or check updates', snapStates.settings.autoRefresh); 213 + console.log('✨ Load or check updates', { 214 + autoRefresh: snapStates.settings.autoRefresh, 215 + scrollTop: scrollableRef.current.scrollTop, 216 + disableHoverCheck, 217 + idle, 218 + inBackground: inBackground(), 219 + }); 211 220 if ( 212 221 snapStates.settings.autoRefresh && 213 222 scrollableRef.current.scrollTop === 0 && 214 - (disableHoverCheck || !isHovering.current) && 223 + (disableHoverCheck || idle) && 215 224 !inBackground() 216 225 ) { 217 226 console.log('✨ Load updates', snapStates.settings.autoRefresh); ··· 225 234 } 226 235 } 227 236 }, 228 - [id, loadItems, checkForUpdates, snapStates.settings.autoRefresh], 237 + [id, idle, loadItems, checkForUpdates, snapStates.settings.autoRefresh], 229 238 ); 230 239 231 240 const lastHiddenTime = useRef();
+5 -1
src/pages/notifications.jsx
··· 1 1 import './notifications.css'; 2 2 3 + import { useIdle } from '@uidotdev/usehooks'; 3 4 import { memo } from 'preact/compat'; 4 5 import { useCallback, useEffect, useRef, useState } from 'preact/hooks'; 5 6 import { useSnapshot } from 'valtio'; ··· 146 147 }, [nearReachEnd, showMore]); 147 148 148 149 const isHovering = useRef(false); 150 + const idle = useIdle(5000); 151 + console.debug('🧘‍♀️ IDLE', idle); 149 152 const loadUpdates = useCallback(() => { 150 153 console.log('✨ Load updates', { 151 154 autoRefresh: snapStates.settings.autoRefresh, ··· 158 161 if ( 159 162 snapStates.settings.autoRefresh && 160 163 scrollableRef.current?.scrollTop === 0 && 161 - !isHovering.current && 164 + (!isHovering.current || idle) && 162 165 !inBackground() && 163 166 snapStates.notificationsShowNew && 164 167 uiState !== 'loading' ··· 166 169 loadNotifications(true); 167 170 } 168 171 }, [ 172 + idle, 169 173 snapStates.notificationsShowNew, 170 174 snapStates.settings.autoRefresh, 171 175 uiState,