App.jsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import * as Routes from './routes';
  2. import { h } from 'preact';
  3. import ActivityIndicator from './components/ActivityIndicator';
  4. import AsyncRoute from 'preact-async-route';
  5. import AppBar from './AppBar';
  6. import Cameras from './routes/Cameras';
  7. import { Router } from 'preact-router';
  8. import Sidebar from './Sidebar';
  9. import { DarkModeProvider, DrawerProvider } from './context';
  10. import { FetchStatus, useConfig } from './api';
  11. export default function App() {
  12. const { status } = useConfig();
  13. return (
  14. <DarkModeProvider>
  15. <DrawerProvider>
  16. <div data-testid="app" className="w-full">
  17. <AppBar />
  18. {status !== FetchStatus.LOADED ? (
  19. <div className="flex flex-grow-1 min-h-screen justify-center items-center">
  20. <ActivityIndicator />
  21. </div>
  22. ) : (
  23. <div className="flex flex-row min-h-screen w-full bg-white dark:bg-gray-900 text-gray-900 dark:text-white">
  24. <Sidebar />
  25. <div className="w-full flex-auto p-2 mt-16 px-4 min-w-0">
  26. <Router>
  27. <AsyncRoute path="/cameras/:camera/editor" getComponent={Routes.getCameraMap} />
  28. <AsyncRoute path="/cameras/:camera" getComponent={Routes.getCamera} />
  29. <AsyncRoute path="/birdseye" getComponent={Routes.getBirdseye} />
  30. <AsyncRoute path="/events" getComponent={Routes.getEvents} />
  31. <AsyncRoute path="/recording/:camera/:date?/:hour?/:seconds?" getComponent={Routes.getRecording} />
  32. <AsyncRoute path="/debug" getComponent={Routes.getDebug} />
  33. <AsyncRoute path="/styleguide" getComponent={Routes.getStyleGuide} />
  34. <Cameras default path="/" />
  35. </Router>
  36. </div>
  37. </div>
  38. )}
  39. </div>
  40. </DrawerProvider>
  41. </DarkModeProvider>
  42. );
  43. }