Sidebar.jsx 1.6 KB

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