2021-01-09 18:26:46 +01:00
|
|
|
import { h } from 'preact';
|
|
|
|
import Camera from './Camera';
|
|
|
|
import CameraMap from './CameraMap';
|
|
|
|
import Cameras from './Cameras';
|
|
|
|
import Debug from './Debug';
|
|
|
|
import Event from './Event';
|
|
|
|
import Events from './Events';
|
|
|
|
import { Router } from 'preact-router';
|
|
|
|
import Sidebar from './Sidebar';
|
|
|
|
import { ApiHost, Config } from './context';
|
|
|
|
import { useContext, useEffect, useState } from 'preact/hooks';
|
|
|
|
|
|
|
|
export default function App() {
|
|
|
|
const apiHost = useContext(ApiHost);
|
|
|
|
const [config, setConfig] = useState(null);
|
|
|
|
|
|
|
|
useEffect(async () => {
|
|
|
|
const response = await fetch(`${apiHost}/api/config`);
|
|
|
|
const data = response.ok ? await response.json() : {};
|
|
|
|
setConfig(data);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return !config ? (
|
|
|
|
<div />
|
|
|
|
) : (
|
|
|
|
<Config.Provider value={config}>
|
2021-01-18 19:49:00 +01:00
|
|
|
<div className="flex md:min-h-screen w-full bg-gray-100 dark:bg-gray-800">
|
2021-01-09 18:26:46 +01:00
|
|
|
<Sidebar />
|
2021-01-18 19:49:00 +01:00
|
|
|
<div className="p-4 min-w-0">
|
2021-01-09 18:26:46 +01:00
|
|
|
<Router>
|
2021-01-15 21:29:30 +01:00
|
|
|
<CameraMap path="/cameras/:camera/editor" />
|
2021-01-09 18:26:46 +01:00
|
|
|
<Camera path="/cameras/:camera" />
|
|
|
|
<Event path="/events/:eventId" />
|
|
|
|
<Events path="/events" />
|
|
|
|
<Debug path="/debug" />
|
|
|
|
<Cameras path="/" />
|
|
|
|
</Router>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Config.Provider>
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|