Sidebar.jsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.entries(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. <Match path="/recording/:camera/:date?/:hour?/:seconds?">
  29. {({ matches }) =>
  30. matches ? (
  31. <Fragment>
  32. <Separator />
  33. {cameras.map(([camera, conf]) => {
  34. if (conf.record.enabled) {
  35. return (
  36. <Destination
  37. path={`/recording/${camera}/:date?/:hour?/:seconds?`}
  38. href={`/recording/${camera}`}
  39. text={camera}
  40. />
  41. );
  42. }
  43. return null;
  44. })}
  45. <Separator />
  46. </Fragment>
  47. ) : null
  48. }
  49. </Match>
  50. <Destination href="/birdseye" text="Birdseye" />
  51. <Destination href="/events" text="Events" />
  52. <Destination href="/debug" text="Debug" />
  53. <Separator />
  54. <div className="flex flex-grow" />
  55. {ENV !== 'production' ? (
  56. <Fragment>
  57. <Destination href="/styleguide" text="Style Guide" />
  58. <Separator />
  59. </Fragment>
  60. ) : null}
  61. <Destination className="self-end" href="https://blakeblackshear.github.io/frigate" text="Documentation" />
  62. <Destination className="self-end" href="https://github.com/blakeblackshear/frigate" text="GitHub" />
  63. </NavigationDrawer>
  64. );
  65. }
  66. const Header = memo(() => {
  67. return (
  68. <div className="text-gray-500">
  69. <LinkedLogo />
  70. </div>
  71. );
  72. });