mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-11-25 18:55:44 +03:00
Try useIdle
This commit is contained in:
parent
e26473f607
commit
fa21eec06a
2 changed files with 17 additions and 4 deletions
|
@ -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();
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue