Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

861 B
Raw Blame
import { useSyncExternalStore } from 'react'
import {
  isEffectivelyOffline,
  isForcedOffline,
  setForcedOffline,
  onNetworkModeChange,
} from '../sync/networkMode'

/**
 * React binding for the global network mode. Re-renders when the browser goes
 * online/offline or the user toggles force-offline.
 *
 *   offline    — the effective offline state (real disconnection OR forced)
 *   forced     — whether the user has the force-offline switch on
 *   setForced  — flip the force-offline switch
 */
export function useNetworkMode(): { offline: boolean; forced: boolean; setForced: (v: boolean) => void } {
  const offline = useSyncExternalStore(onNetworkModeChange, isEffectivelyOffline, () => true)
  const forced = useSyncExternalStore(onNetworkModeChange, isForcedOffline, () => false)
  return { offline, forced, setForced: setForcedOffline }
}