import { Field, Form, Formik } from "formik"; import FormGroup from "../components/FormGroup"; import type { FormValues, Hotlist } from "../../../types/types"; import { useSoundContext } from "../../../context/SoundContext"; import { useCameraBlackboard } from "../../../hooks/useCameraBlackboard"; import { toast } from "sonner"; import SliderComponent from "../../UI/Slider"; import { useFileUpload } from "../../../hooks/useFileUpload"; import { useSound } from "react-sounds"; import { useEffect, useState } from "react"; const SoundSettingsFields = () => { const { state, dispatch } = useSoundContext(); const { mutation } = useCameraBlackboard(); const [test, setTest] = useState(""); const { play } = useSound(test); const { query } = useFileUpload({ queryKey: state.sightingSound ? [state.sightingSound] : undefined, }); const hotlists: Hotlist[] = state.hotlists; const soundOptions = state?.soundOptions?.map((soundOption) => ({ value: soundOption?.soundFileName, label: soundOption?.name, })); const initialValues: FormValues = { sightingSound: state.sightingSound ?? "switch", NPEDsound: state.NPEDsound ?? "popup", hotlistSound: state.hotlistSound ?? "notification", hotlists, }; useEffect(() => { setTest(test); }, [test]); const handletest = () => { console.log(test); play({ volume: 1 }); query?.refetch(); }; const handleSubmit = async (values: FormValues) => { console.log(query?.data); const url = query?.data ? URL.createObjectURL(query.data) : ""; // const audio = new Audio(url); // console.log(audio); setTest(url); const updatedValues = { ...values, sightingVolume: state.sightingVolume, NPEDsoundVolume: state.NPEDsoundVolume, hotlistSoundVolume: state.hotlistSoundVolume, soundOptions: [...(state.soundOptions ?? [])], }; dispatch({ type: "UPDATE", payload: updatedValues }); const result = await mutation.mutateAsync({ operation: "INSERT", path: "soundSettings", value: updatedValues, }); if (result.reason !== "OK") { toast.error("Cannot update sound settings"); } else { toast.success("Sound Settings successfully updated"); } }; return ( {() => (
{soundOptions?.map(({ value, label }) => { return ( ); })}
{soundOptions?.map(({ value, label }) => ( ))}

Hotlist Sounds

{soundOptions?.map(({ value, label }) => ( ))}
{/* (
{values?.hotlists?.length > 0 ? ( values?.hotlists?.map((hotlist, index) => (
{soundOptions?.map(({ value, label }) => ( ))}
)) ) : (

No hotlists yet, Add one

)}
)} />
*/}
)}
); }; export default SoundSettingsFields;