import { h } from 'preact';
import AutoUpdatingCameraImage from '../components/AutoUpdatingCameraImage';
import Button from '../components/Button';
import Card from '../components/Card';
import Heading from '../components/Heading';
import Link from '../components/Link';
import SettingsIcon from '../icons/Settings';
import Switch from '../components/Switch';
import { route } from 'preact-router';
import { usePersistence } from '../context';
import { useCallback, useContext, useMemo, useState } from 'preact/hooks';
import { useApiHost, useConfig } from '../api';
export default function Camera({ camera }) {
const { data: config } = useConfig();
const apiHost = useApiHost();
const [showSettings, setShowSettings] = useState(false);
if (!config) {
return
{`No camera named ${camera}`}
;
}
const cameraConfig = config.cameras[camera];
const [options, setOptions, optionsLoaded] = usePersistence(`${camera}-feed`, Object.freeze({}));
const objectCount = useMemo(() => cameraConfig.objects.track.length, [cameraConfig]);
const handleSetOption = useCallback(
(id, value) => {
const newOptions = { ...options, [id]: value };
setOptions(newOptions);
},
[options]
);
const searchParams = useMemo(
() =>
new URLSearchParams(
Object.keys(options).reduce((memo, key) => {
memo.push([key, options[key] === true ? '1' : '0']);
return memo;
}, [])
),
[camera, options]
);
const handleToggleSettings = useCallback(() => {
setShowSettings(!showSettings);
}, [showSettings, setShowSettings]);
const optionContent = showSettings ? (
Bounding box
Timestamp
Zones
Masks
Motion boxes
Regions
Mask & Zone creator
) : null;
return (
{camera}
{optionsLoaded ? (
) : null}
{showSettings ?
: null}
Tracked objects
{cameraConfig.objects.track.map((objectType) => (
}
/>
))}
);
}