forked from commaai/new-connect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
56 lines (45 loc) · 1.69 KB
/
App.tsx
File metadata and controls
56 lines (45 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { createSignal, lazy, onCleanup, Show, Suspense, type ParentComponent, type VoidComponent } from 'solid-js'
import { Router, Route } from '@solidjs/router'
import { QueryClientProvider } from '@tanstack/solid-query'
import { SolidQueryDevtools } from '@tanstack/solid-query-devtools'
import { getAppQueryClient } from '~/api/query-client'
import 'leaflet/dist/leaflet.css'
const Login = lazy(() => import('./pages/auth/login'))
const Logout = lazy(() => import('./pages/auth/logout'))
const Auth = lazy(() => import('./pages/auth/auth'))
const Dashboard = lazy(() => import('./pages/dashboard'))
import OfflinePage from '~/pages/offline'
export const Routes = () => (
<>
<Route path="/login" component={Login} />
<Route path="/logout" component={Logout} />
<Route path="/auth" component={Auth} />
<Route path="/*dongleId" component={Dashboard} />
</>
)
export const AppLayout: ParentComponent = (props) => {
const [isOnline, setIsOnline] = createSignal(navigator.onLine)
const handleOnline = () => setIsOnline(true)
const handleOffline = () => setIsOnline(false)
window.addEventListener('online', handleOnline)
window.addEventListener('offline', handleOffline)
onCleanup(() => {
window.removeEventListener('online', handleOnline)
window.removeEventListener('offline', handleOffline)
})
return (
<Show when={isOnline()} fallback={<OfflinePage />}>
<Suspense>{props.children}</Suspense>
</Show>
)
}
const queryClient = getAppQueryClient()
const App: VoidComponent = () => (
<QueryClientProvider client={queryClient}>
<SolidQueryDevtools />
<Router root={AppLayout}>
<Routes />
</Router>
</QueryClientProvider>
)
export default App