2021-02-04 00:15:27 +01:00
|
|
|
import { h, Fragment } from 'preact';
|
2021-02-02 05:28:25 +01:00
|
|
|
import LinkedLogo from './components/LinkedLogo';
|
2021-02-04 19:13:47 +01:00
|
|
|
import { Match } from 'preact-router/match';
|
|
|
|
import { memo } from 'preact/compat';
|
2021-02-14 05:37:22 +01:00
|
|
|
import { ENV } from './env';
|
2022-04-15 14:23:02 +02:00
|
|
|
import { useMemo } from 'preact/hooks'
|
2022-02-26 20:11:00 +01:00
|
|
|
import useSWR from 'swr';
|
2021-02-04 19:13:47 +01:00
|
|
|
import NavigationDrawer, { Destination, Separator } from './components/NavigationDrawer';
|
|
|
|
|
|
|
|
export default function Sidebar() {
|
2022-02-26 20:11:00 +01:00
|
|
|
const { data: config } = useSWR('config');
|
2022-04-15 14:23:02 +02:00
|
|
|
|
|
|
|
const sortedCameras = useMemo(() => {
|
|
|
|
if (!config) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return Object.entries(config.cameras)
|
|
|
|
.filter(([_, conf]) => conf.ui.dashboard)
|
|
|
|
.sort(([_, aConf], [__, bConf]) => aConf.ui.order - bConf.ui.order);
|
|
|
|
}, [config]);
|
|
|
|
|
2022-03-06 05:16:31 +01:00
|
|
|
if (!config) {
|
|
|
|
return null;
|
|
|
|
}
|
2022-04-15 14:23:02 +02:00
|
|
|
const { birdseye } = config;
|
2021-01-09 18:26:46 +01:00
|
|
|
|
|
|
|
return (
|
2021-02-04 19:13:47 +01:00
|
|
|
<NavigationDrawer header={<Header />}>
|
|
|
|
<Destination href="/" text="Cameras" />
|
2021-02-05 00:19:47 +01:00
|
|
|
<Match path="/cameras/:camera/:other?">
|
2021-02-04 19:13:47 +01:00
|
|
|
{({ matches }) =>
|
|
|
|
matches ? (
|
2022-04-15 14:23:02 +02:00
|
|
|
<CameraSection sortedCameras={sortedCameras} />
|
2021-02-04 19:13:47 +01:00
|
|
|
) : null
|
|
|
|
}
|
|
|
|
</Match>
|
2021-06-03 19:02:40 +02:00
|
|
|
<Match path="/recording/:camera/:date?/:hour?/:seconds?">
|
2021-05-28 19:13:48 +02:00
|
|
|
{({ matches }) =>
|
|
|
|
matches ? (
|
2022-04-15 14:23:02 +02:00
|
|
|
<RecordingSection sortedCameras={sortedCameras} />
|
2021-05-28 19:13:48 +02:00
|
|
|
) : null
|
|
|
|
}
|
|
|
|
</Match>
|
2021-08-30 18:21:20 +02:00
|
|
|
{birdseye?.enabled ? <Destination href="/birdseye" text="Birdseye" /> : null}
|
2021-02-04 19:13:47 +01:00
|
|
|
<Destination href="/events" text="Events" />
|
|
|
|
<Destination href="/debug" text="Debug" />
|
|
|
|
<Separator />
|
|
|
|
<div className="flex flex-grow" />
|
2021-02-14 05:37:22 +01:00
|
|
|
{ENV !== 'production' ? (
|
2021-02-07 22:46:05 +01:00
|
|
|
<Fragment>
|
|
|
|
<Destination href="/styleguide" text="Style Guide" />
|
|
|
|
<Separator />
|
|
|
|
</Fragment>
|
|
|
|
) : null}
|
2021-10-01 14:37:47 +02:00
|
|
|
<Destination className="self-end" href="https://docs.frigate.video" text="Documentation" />
|
2021-02-04 19:13:47 +01:00
|
|
|
<Destination className="self-end" href="https://github.com/blakeblackshear/frigate" text="GitHub" />
|
|
|
|
</NavigationDrawer>
|
2021-01-09 18:26:46 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-04-15 14:23:02 +02:00
|
|
|
function CameraSection({ sortedCameras }) {
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<Separator />
|
|
|
|
{sortedCameras.map(([camera]) => (
|
2022-08-25 13:44:34 +02:00
|
|
|
<Destination key={camera} href={`/cameras/${camera}`} text={camera.replaceAll('_', ' ')} />
|
2022-04-15 14:23:02 +02:00
|
|
|
))}
|
|
|
|
<Separator />
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function RecordingSection({ sortedCameras }) {
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<Separator />
|
|
|
|
{sortedCameras.map(([camera, _]) => {
|
|
|
|
return (
|
|
|
|
<Destination
|
|
|
|
key={camera}
|
|
|
|
path={`/recording/${camera}/:date?/:hour?/:seconds?`}
|
|
|
|
href={`/recording/${camera}`}
|
2022-08-25 13:44:34 +02:00
|
|
|
text={camera.replaceAll('_', ' ')}
|
2022-04-15 14:23:02 +02:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
<Separator />
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-09 20:35:33 +01:00
|
|
|
const Header = memo(() => {
|
2021-01-09 18:26:46 +01:00
|
|
|
return (
|
2021-02-09 20:35:33 +01:00
|
|
|
<div className="text-gray-500">
|
2021-02-04 19:13:47 +01:00
|
|
|
<LinkedLogo />
|
|
|
|
</div>
|
2021-01-09 18:26:46 +01:00
|
|
|
);
|
2022-04-15 14:23:02 +02:00
|
|
|
});
|