2021-01-09 18:26:46 +01:00
|
|
|
import { h } from 'preact';
|
2021-02-07 22:46:05 +01:00
|
|
|
import ActivityIndicator from '../components/ActivityIndicator';
|
|
|
|
import Card from '../components/Card';
|
|
|
|
import CameraImage from '../components/CameraImage';
|
2021-02-09 20:35:33 +01:00
|
|
|
import { useConfig, FetchStatus } from '../api';
|
2021-02-02 05:28:25 +01:00
|
|
|
import { useMemo } from 'preact/hooks';
|
2021-01-09 18:26:46 +01:00
|
|
|
|
|
|
|
export default function Cameras() {
|
2021-01-26 16:04:03 +01:00
|
|
|
const { data: config, status } = useConfig();
|
2021-01-09 18:26:46 +01:00
|
|
|
|
2021-02-09 20:35:33 +01:00
|
|
|
return status !== FetchStatus.LOADED ? (
|
|
|
|
<ActivityIndicator />
|
|
|
|
) : (
|
2021-02-04 00:35:28 +01:00
|
|
|
<div className="grid grid-cols-1 3xl:grid-cols-3 md:grid-cols-2 gap-4">
|
2021-01-09 18:26:46 +01:00
|
|
|
{Object.keys(config.cameras).map((camera) => (
|
|
|
|
<Camera name={camera} />
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function Camera({ name }) {
|
|
|
|
const href = `/cameras/${name}`;
|
2021-02-02 05:28:25 +01:00
|
|
|
const buttons = useMemo(() => [{ name: 'Events', href: `/events?camera=${name}` }], [name]);
|
2021-01-09 18:26:46 +01:00
|
|
|
|
2021-02-13 16:24:53 +01:00
|
|
|
return <Card buttons={buttons} href={href} header={name} media={<CameraImage camera={name} stretch />} />;
|
2021-01-09 18:26:46 +01:00
|
|
|
}
|