import { faCheck, faExclamation, faWifi, } from '@fortawesome/free-solid-svg-icons' import { Popover } from '@headlessui/react' import { useEffect, useState } from 'react' import { ActionIcon } from './ActionIcon' export const NETWORK_CONTENT = { good: 'Network health is good', bad: 'Network issue', } const NETWORK_MESSAGES = { offline: 'You are offline', } export const NetworkHealthIndicator = () => { const [networkIssues, setNetworkIssues] = useState([]) const hasIssues = [...networkIssues.values()].length > 0 useEffect(() => { const offlineListener = () => setNetworkIssues((issues) => { return [ ...issues.filter((issue) => issue !== NETWORK_MESSAGES.offline), NETWORK_MESSAGES.offline, ] }) window.addEventListener('offline', offlineListener) const onlineListener = () => setNetworkIssues((issues) => { return [...issues.filter((issue) => issue !== NETWORK_MESSAGES.offline)] }) window.addEventListener('online', onlineListener) return () => { window.removeEventListener('offline', offlineListener) window.removeEventListener('online', onlineListener) } }, []) return ( Network Health {!hasIssues ? ( {NETWORK_CONTENT.good} ) : (
    {NETWORK_CONTENT.bad} {networkIssues.length > 1 ? 's' : ''} {networkIssues.map((issue) => (
  • {issue}

  • ))}
)}
) }