import { useCallback, useMemo, useState } from "react"; import AutoUpdatingCameraImage from "./AutoUpdatingCameraImage"; import { CameraConfig } from "../../../types/frigateConfig"; import { usePersistence } from "../../../hooks/use-persistence"; import { Button, Switch, Text } from "@mantine/core"; import { Card, CardContent, CardHeader, CardTitle } from "./card"; import { IconSettings } from "@tabler/icons-react"; type Options = { [key: string]: boolean }; const emptyObject = Object.freeze({}); type DebugCameraImageProps = { className?: string; cameraConfig: CameraConfig url: string }; export default function DebugCameraImage({ className, cameraConfig, url, }: DebugCameraImageProps) { const [showSettings, setShowSettings] = useState(false); const [options, setOptions] = usePersistence( `${cameraConfig?.name}-feed`, emptyObject ); const handleSetOption = useCallback( (id: string, value: boolean) => { const newOptions = { ...options, [id]: value }; setOptions(newOptions); }, [options] ); const searchParams = useMemo( () => new URLSearchParams( Object.keys(options).reduce((memo, key) => { //@ts-ignore we know this is correct memo.push([key, options[key] === true ? "1" : "0"]); return memo; }, []) ), [options] ); const handleToggleSettings = useCallback(() => { setShowSettings(!showSettings); }, [showSettings]); return (
{showSettings ? ( Options ) : null}
); } type DebugSettingsProps = { handleSetOption: (id: string, value: boolean) => void; options: Options; }; function DebugSettings({ handleSetOption, options }: DebugSettingsProps) { return (
{ }} // onCheckedChange={(isChecked) => { // handleSetOption("bbox", isChecked); // }} /> {/* */} Bounding Box
{ // handleSetOption("timestamp", isChecked); // }} /> {/* */} Timestamp
{ // handleSetOption("zones", isChecked); // }} /> {/* */} Zones
{ // handleSetOption("mask", isChecked); // }} /> {/* */} Mask
{ // handleSetOption("motion", isChecked); // }} /> {/* */} Motion
{ // handleSetOption("regions", isChecked); // }} /> {/* */} Regions
); }