import { Switch } from "../ui/switch"; import { Label } from "../ui/label"; import { CameraConfig } from "@/types/frigateConfig"; import { Button } from "../ui/button"; import { LuSettings } from "react-icons/lu"; import { useCallback, useMemo, useState } from "react"; import { Card, CardContent, CardHeader, CardTitle } from "../ui/card"; import { usePersistence } from "@/hooks/use-persistence"; import AutoUpdatingCameraImage from "./AutoUpdatingCameraImage"; type Options = { [key: string]: boolean }; const emptyObject = Object.freeze({}); type DebugCameraImageProps = { className?: string; cameraConfig: CameraConfig; }; export default function DebugCameraImage({ className, cameraConfig, }: 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, setOptions], ); const searchParams = useMemo( () => new URLSearchParams( Object.keys(options || {}).reduce((memo, key) => { //@ts-expect-error 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 (
{ handleSetOption("bbox", isChecked); }} />
{ handleSetOption("timestamp", isChecked); }} />
{ handleSetOption("zones", isChecked); }} />
{ handleSetOption("mask", isChecked); }} />
{ handleSetOption("motion", isChecked); }} />
{ handleSetOption("regions", isChecked); }} />
); }