feat: add machine info page

This commit is contained in:
Aarnav Tale
2024-03-26 09:28:52 -04:00
parent b8498a9db3
commit 3b1f0ae6f8
5 changed files with 162 additions and 16 deletions
+19 -1
View File
@@ -1,4 +1,5 @@
import { useRevalidator } from '@remix-run/react'
import { useEffect } from 'react'
import { useInterval } from 'usehooks-ts'
type Properties = {
@@ -7,10 +8,27 @@ type Properties = {
export function useLiveData({ interval }: Properties) {
const revalidator = useRevalidator()
// Handle normal stale-while-revalidate behavior
useInterval(() => {
if (revalidator.state === 'idle') {
revalidator.revalidate()
}
}, interval)
}
useEffect(() => {
const handler = () => {
if (revalidator.state === 'idle') {
revalidator.revalidate()
}
}
window.addEventListener('online', handler)
document.addEventListener('focus', handler)
return () => {
window.removeEventListener('online', handler)
document.removeEventListener('focus', handler)
}
}, [revalidator])
}