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[]) => 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 { mutate: mutateConfig } = useSWR("config", { revalidateOnFocus: false, }); const handleClose = useCallback(() => { setShowWizard(false); // Delay to let CameraWizardDialog's config save and go2rtc setup complete, // then force a fresh fetch from the server (bypassing SWR cache) 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(() => { // Fetch failed, stay on this step }); }, 1000); }, [mutateConfig, addedCameras]); const handleNext = useCallback(() => { onNext(addedCameras.length > 0 ? addedCameras : undefined); }, [onNext, addedCameras]); return ( <>

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

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

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