Sidebar.jsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { h, Fragment } from 'preact';
  2. import LinkedLogo from './components/LinkedLogo';
  3. import { Match } from 'preact-router/match';
  4. import { memo } from 'preact/compat';
  5. import { ENV } from './env';
  6. import { useConfig } from './api';
  7. import { useMemo } from 'preact/hooks';
  8. import NavigationDrawer, { Destination, Separator } from './components/NavigationDrawer';
  9. export default function Sidebar() {
  10. const { data: config } = useConfig();
  11. const cameras = useMemo(() => Object.keys(config.cameras), [config]);
  12. return (
  13. <NavigationDrawer header={<Header />}>
  14. <Destination href="/" text="Cameras" />
  15. <Match path="/cameras/:camera/:other?">
  16. {({ matches }) =>
  17. matches ? (
  18. <Fragment>
  19. <Separator />
  20. {cameras.map((camera) => (
  21. <Destination href={`/cameras/${camera}`} text={camera} />
  22. ))}
  23. <Separator />
  24. </Fragment>
  25. ) : null
  26. }
  27. </Match>
  28. <Destination href="/events" text="Events" />
  29. <Destination href="/debug" text="Debug" />
  30. <Separator />
  31. <div className="flex flex-grow" />
  32. {ENV !== 'production' ? (
  33. <Fragment>
  34. <Destination href="/styleguide" text="Style Guide" />
  35. <Separator />
  36. </Fragment>
  37. ) : null}
  38. <Destination className="self-end" href="https://blakeblackshear.github.io/frigate" text="Documentation" />
  39. <Destination className="self-end" href="https://github.com/blakeblackshear/frigate" text="GitHub" />
  40. </NavigationDrawer>
  41. );
  42. }
  43. const Header = memo(() => {
  44. return (
  45. <div className="text-gray-500">
  46. <LinkedLogo />
  47. </div>
  48. );
  49. });