Some checks failed
E2E / Playwright e2e (push) Has been cancelled
Move mail, compose, contacts, and accounts off mocks onto REST + WS. Add client, auth store, IDB-backed query cache, offline queue, and sync bar; hybrid Zustand for UI-only state. Settings still local until backend has preferences API.
26 lines
569 B
TypeScript
26 lines
569 B
TypeScript
"use client"
|
|
|
|
import { useSyncExternalStore } from "react"
|
|
|
|
function subscribe(callback: () => void) {
|
|
window.addEventListener("online", callback)
|
|
window.addEventListener("offline", callback)
|
|
return () => {
|
|
window.removeEventListener("online", callback)
|
|
window.removeEventListener("offline", callback)
|
|
}
|
|
}
|
|
|
|
function getSnapshot() {
|
|
return navigator.onLine
|
|
}
|
|
|
|
function getServerSnapshot() {
|
|
return true
|
|
}
|
|
|
|
export function useNetworkStatus() {
|
|
const isOnline = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)
|
|
return { isOnline }
|
|
}
|