import CameraWizardDialog from "@/components/settings/CameraWizardDialog"; import { Button } from "@/components/ui/button"; import { useCallback, useState } from "react"; import { useTranslation } from "react-i18next"; import useSWR from "swr"; import { FrigateConfig } from "@/types/frigateConfig"; import { FaCircleCheck } from "react-icons/fa6"; type SetupCameraProps = { onNext: ( cameraNames?: string[], detectCodecs?: Record, ) => void; onBack: () => void; }; export default function SetupCamera({ onNext, onBack }: SetupCameraProps) { const { t } = useTranslation(["views/setup"]); const [showWizard, setShowWizard] = useState(false); const [addedCameras, setAddedCameras] = useState([]); const [detectCodecs, setDetectCodecs] = useState>({}); const { mutate: mutateConfig } = useSWR("config", { revalidateOnFocus: false, }); const handleClose = useCallback(() => { setShowWizard(false); // the dialog's config save and go2rtc setup need a moment to land, and // the SWR cache would serve the pre-save config setTimeout(() => { fetch(`${window.baseUrl || ""}api/config`) .then((res) => res.json()) .then((freshConfig: FrigateConfig) => { const cameraNames = Object.keys(freshConfig.cameras || {}); if (cameraNames.length > addedCameras.length) { mutateConfig(freshConfig, { revalidate: false }); setAddedCameras(cameraNames); } }) .catch(() => {}); }, 1000); }, [mutateConfig, addedCameras]); const handleCameraAdded = useCallback( ({ name, detectCodec }: { name: string; detectCodec?: string }) => { if (detectCodec) { setDetectCodecs((previous) => ({ ...previous, [name]: detectCodec })); } }, [], ); const handleNext = useCallback(() => { onNext(addedCameras.length > 0 ? addedCameras : undefined, detectCodecs); }, [onNext, addedCameras, detectCodecs]); return ( <>

{t("setupWizard.camera.title")}

{t("setupWizard.camera.description")}

{addedCameras.length > 0 && (
{addedCameras.map((name) => (
{name}
))}
)}
{addedCameras.length > 0 && ( )}
); }