blakeblackshear.frigate/web/src/Camera.jsx

69 lines
2.6 KiB
React
Raw Normal View History

2021-01-09 18:26:46 +01:00
import { h } from 'preact';
import AutoUpdatingCameraImage from './components/AutoUpdatingCameraImage';
import Box from './components/Box';
2021-01-09 18:26:46 +01:00
import Heading from './components/Heading';
import Link from './components/Link';
import Switch from './components/Switch';
import { route } from 'preact-router';
import { useCallback, useContext } from 'preact/hooks';
2021-01-26 16:04:03 +01:00
import { useApiHost, useConfig } from './api';
2021-01-09 18:26:46 +01:00
export default function Camera({ camera, url }) {
2021-01-26 16:04:03 +01:00
const { data: config } = useConfig();
const apiHost = useApiHost();
2021-01-09 18:26:46 +01:00
2021-01-26 16:04:03 +01:00
if (!config) {
2021-01-09 18:26:46 +01:00
return <div>{`No camera named ${camera}`}</div>;
}
const cameraConfig = config.cameras[camera];
const { pathname, searchParams } = new URL(`${window.location.protocol}//${window.location.host}${url}`);
const searchParamsString = searchParams.toString();
const handleSetOption = useCallback(
(id, value) => {
searchParams.set(id, value ? 1 : 0);
route(`${pathname}?${searchParams.toString()}`, true);
},
[searchParams]
);
function getBoolean(id) {
return Boolean(parseInt(searchParams.get(id), 10));
}
return (
<div className="space-y-4">
2021-01-09 18:26:46 +01:00
<Heading size="2xl">{camera}</Heading>
<Box>
<AutoUpdatingCameraImage camera={camera} searchParams={searchParamsString} />
</Box>
<Box className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4 p-4">
2021-01-09 18:26:46 +01:00
<Switch checked={getBoolean('bbox')} id="bbox" label="Bounding box" onChange={handleSetOption} />
<Switch checked={getBoolean('timestamp')} id="timestamp" label="Timestamp" onChange={handleSetOption} />
<Switch checked={getBoolean('zones')} id="zones" label="Zones" onChange={handleSetOption} />
<Switch checked={getBoolean('mask')} id="mask" label="Masks" onChange={handleSetOption} />
<Switch checked={getBoolean('motion')} id="motion" label="Motion boxes" onChange={handleSetOption} />
<Switch checked={getBoolean('regions')} id="regions" label="Regions" onChange={handleSetOption} />
<Link href={`/cameras/${camera}/editor`}>Mask & Zone creator</Link>
</Box>
<div className="space-y-4">
2021-01-09 18:26:46 +01:00
<Heading size="sm">Tracked objects</Heading>
<div className="grid grid-cols-3 md:grid-cols-4 gap-4">
2021-01-09 18:26:46 +01:00
{cameraConfig.objects.track.map((objectType) => {
return (
<Box key={objectType} hover href={`/events?camera=${camera}&label=${objectType}`}>
<Heading size="sm">{objectType}</Heading>
<img src={`${apiHost}/api/${camera}/${objectType}/best.jpg?crop=1&h=150`} />
</Box>
2021-01-09 18:26:46 +01:00
);
})}
</div>
2021-01-09 18:26:46 +01:00
</div>
</div>
);
}