diff --git a/app/components/Attribute.tsx b/app/components/Attribute.tsx new file mode 100644 index 0000000..604a6c9 --- /dev/null +++ b/app/components/Attribute.tsx @@ -0,0 +1,39 @@ +import { ClipboardIcon } from '@heroicons/react/24/outline' +import toast from 'react-hot-toast/headless' + +type Properties = { + readonly name: string; + readonly value: string; + readonly isCopyable?: boolean; +} + +export default function Attribute({ name, value, isCopyable }: Properties) { + const canCopy = isCopyable ?? false + return ( +
+ + All Machines + + {' / '} + {data.givenName} +
+ +{machine.online ? 'Connected' diff --git a/app/utils/useLiveData.ts b/app/utils/useLiveData.ts index d0d0824..e3e1793 100644 --- a/app/utils/useLiveData.ts +++ b/app/utils/useLiveData.ts @@ -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]) +}