2021-02-08 00:46:05 +03:00
|
|
|
import * as Routes from './routes';
|
2021-01-09 20:26:46 +03:00
|
|
|
import { h } from 'preact';
|
2021-01-30 19:52:37 +03:00
|
|
|
import ActivityIndicator from './components/ActivityIndicator';
|
2021-02-08 00:46:05 +03:00
|
|
|
import AsyncRoute from 'preact-async-route';
|
2021-02-11 00:21:43 +03:00
|
|
|
import AppBar from './AppBar';
|
2021-02-08 00:46:05 +03:00
|
|
|
import Cameras from './routes/Cameras';
|
2021-01-09 20:26:46 +03:00
|
|
|
import { Router } from 'preact-router';
|
|
|
|
|
import Sidebar from './Sidebar';
|
2021-02-04 21:13:47 +03:00
|
|
|
import { DarkModeProvider, DrawerProvider } from './context';
|
2021-02-09 22:35:33 +03:00
|
|
|
import { FetchStatus, useConfig } from './api';
|
2021-01-09 20:26:46 +03:00
|
|
|
|
|
|
|
|
export default function App() {
|
2022-01-13 21:50:01 +03:00
|
|
|
const { status, data: config } = useConfig();
|
2022-01-13 23:28:23 +03:00
|
|
|
const cameraComponent = config && config.ui.use_experimental ? Routes.getCameraV2 : Routes.getCamera;
|
2021-02-02 07:28:25 +03:00
|
|
|
return (
|
2021-01-31 17:24:04 +03:00
|
|
|
<DarkModeProvider>
|
2021-02-04 21:13:47 +03:00
|
|
|
<DrawerProvider>
|
2022-01-13 21:50:01 +03:00
|
|
|
<div data-testid='app' className='w-full'>
|
2021-02-11 00:21:43 +03:00
|
|
|
<AppBar />
|
2021-02-04 02:15:27 +03:00
|
|
|
{status !== FetchStatus.LOADED ? (
|
2022-01-13 21:50:01 +03:00
|
|
|
<div className='flex flex-grow-1 min-h-screen justify-center items-center'>
|
2021-02-04 02:15:27 +03:00
|
|
|
<ActivityIndicator />
|
2021-01-31 17:24:04 +03:00
|
|
|
</div>
|
2021-02-04 02:15:27 +03:00
|
|
|
) : (
|
2022-01-13 21:50:01 +03:00
|
|
|
<div className='flex flex-row min-h-screen w-full bg-white dark:bg-gray-900 text-gray-900 dark:text-white'>
|
2021-02-04 02:15:27 +03:00
|
|
|
<Sidebar />
|
2022-01-13 21:50:01 +03:00
|
|
|
<div className='w-full flex-auto mt-16 min-w-0'>
|
2021-02-04 02:15:27 +03:00
|
|
|
<Router>
|
2022-01-13 21:50:01 +03:00
|
|
|
<AsyncRoute path='/cameras/:camera/editor' getComponent={Routes.getCameraMap} />
|
|
|
|
|
<AsyncRoute path='/cameras/:camera' getComponent={cameraComponent} />
|
|
|
|
|
<AsyncRoute path='/birdseye' getComponent={Routes.getBirdseye} />
|
|
|
|
|
<AsyncRoute path='/events' getComponent={Routes.getEvents} />
|
|
|
|
|
<AsyncRoute path='/recording/:camera/:date?/:hour?/:seconds?' getComponent={Routes.getRecording} />
|
|
|
|
|
<AsyncRoute path='/debug' getComponent={Routes.getDebug} />
|
|
|
|
|
<AsyncRoute path='/styleguide' getComponent={Routes.getStyleGuide} />
|
|
|
|
|
<Cameras default path='/' />
|
2021-02-04 02:15:27 +03:00
|
|
|
</Router>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2021-02-04 21:13:47 +03:00
|
|
|
</DrawerProvider>
|
2021-01-31 17:24:04 +03:00
|
|
|
</DarkModeProvider>
|
2021-01-09 20:26:46 +03:00
|
|
|
);
|
|
|
|
|
}
|