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 { usePersistence } from '../context'; import { useCallback, useMemo, useState } from 'preact/hooks'; import { useApiHost, useConfig } from '../api'; const emptyObject = Object.freeze({}); export default function Camera({ camera }) { const { data: config } = useConfig(); const apiHost = useApiHost(); const [showSettings, setShowSettings] = useState(false); const cameraConfig = config?.cameras[camera]; const [options, setOptions] = usePersistence(`${camera}-feed`, emptyObject); const handleSetOption = useCallback( (id, value) => { const newOptions = { ...options, [id]: value }; setOptions(newOptions); }, [options, setOptions] ); const searchParams = useMemo( () => new URLSearchParams( Object.keys(options).reduce((memo, key) => { memo.push([key, options[key] === true ? '1' : '0']); return memo; }, []) ), [options] ); const handleToggleSettings = useCallback(() => { setShowSettings(!showSettings); }, [showSettings, setShowSettings]); const optionContent = showSettings ? (
Mask & Zone creator
) : null; return (
{camera}
{showSettings ? : null}
Tracked objects
{cameraConfig.objects.track.map((objectType) => ( } /> ))}
); }