import client from '../api/client' import { deliveryMode } from '../config/server' import { canRediscover, rediscover } from '../native/autoRediscover' import { useState } from 'react' import { useTranslation } from '@xenia/i18n' // Shown at /offline, and (plan step 4.1) instead of the whole app when the server can't be // reached on a start with no cached bootstrap (the app retries by itself and then opens the // screen the address asks for). export default function OfflinePage() { const { t } = useTranslation('waiter') const [checking, setChecking] = useState(false) const [search, setSearch] = useState(null) // null | { done, total } | 'not-found' async function retry() { setChecking(true) try { await client.get('/api/system/health') window.location.href = '/' } catch { setChecking(false) } } // Native app: look for this venue's server at a new address on the same network async function searchNetwork() { setSearch({ done: 0, total: 253 }) const result = await rediscover({ force: true, onProgress: (done, total) => setSearch({ done, total }) }) if (result.status === 'moved' || result.status === 'reachable') { window.location.href = '/' } else { setSearch('not-found') } } const searching = search && search !== 'not-found' return (

📡

{t('offline.title')}

{t('offline.body')}

{canRediscover() && ( )} {search === 'not-found' && (

{t('offline.notFound')}

)} {deliveryMode() === 'native' && ( )}
) }