Skip to content

Commit

Permalink
Disable visibility/focus reload because it's not reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
benmerckx committed Nov 14, 2023
1 parent 513fa1b commit e733590
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions src/dashboard/atoms/DbAtoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,13 @@ export function useDbUpdater(everySeconds = 30) {
const forceDbUpdate = useSetAtom(dbUpdateAtom)
useEffect(() => {
let interval: any = 0
const focus = () => {
if (document.visibilityState === 'hidden') {
disable()
} else {
forceDbUpdate()
enable()
}
}
const enable = () =>
(interval = setInterval(forceDbUpdate, everySeconds * 1000))
const disable = () => clearInterval(interval)
enable()
window.addEventListener('visibilitychange', focus, false)
window.addEventListener('focus', focus, false)
interval = setInterval(forceDbUpdate, everySeconds * 1000)
/*window.addEventListener('visibilitychange', focus, false)
window.addEventListener('focus', focus, false)*/
return () => {
document.removeEventListener('visibilitychange', focus)
document.removeEventListener('focus', focus)
clearInterval(interval)
/*document.removeEventListener('visibilitychange', focus)
document.removeEventListener('focus', focus)*/
}
}, [everySeconds, forceDbUpdate])
}

0 comments on commit e733590

Please sign in to comment.