diff --git a/src/components/SettingForms/Sound/SoundSettingsFields.tsx b/src/components/SettingForms/Sound/SoundSettingsFields.tsx index 41d039e..c2f1fb1 100644 --- a/src/components/SettingForms/Sound/SoundSettingsFields.tsx +++ b/src/components/SettingForms/Sound/SoundSettingsFields.tsx @@ -32,7 +32,6 @@ const SoundSettingsFields = () => { hotlistSoundVolume: state.hotlistSoundVolume, soundOptions: [...(state.soundOptions ?? [])], }; - dispatch({ type: "UPDATE", payload: updatedValues }); const result = await mutation.mutateAsync({ diff --git a/src/components/SettingForms/Sound/SoundUpload.tsx b/src/components/SettingForms/Sound/SoundUpload.tsx index c30d389..30a03e6 100644 --- a/src/components/SettingForms/Sound/SoundUpload.tsx +++ b/src/components/SettingForms/Sound/SoundUpload.tsx @@ -4,16 +4,21 @@ import type { SoundUploadValue } from "../../../types/types"; import { useSoundContext } from "../../../context/SoundContext"; import { toast } from "sonner"; import { useCameraBlackboard } from "../../../hooks/useCameraBlackboard"; +import { useFileUpload } from "../../../hooks/useFileUpload"; const SoundUpload = () => { const { state, dispatch } = useSoundContext(); const { mutation } = useCameraBlackboard(); + const { mutation: fileMutation } = useFileUpload({ + queryKey: state.sightingSound ? [state.sightingSound] : undefined, + }); const initialValues: SoundUploadValue = { name: "", soundFile: null, soundFileName: "", soundUrl: "", + uploadedAt: Date.now(), }; const handleSubmit = async (values: SoundUploadValue) => { @@ -37,10 +42,9 @@ const SoundUpload = () => { path: "soundSettings", value: updatedValues, }); + await fileMutation.mutateAsync(values.soundFile); if (result.reason !== "OK") { toast.error("Cannot update sound settings"); - } else { - toast.success(`${values.name} file added`); } dispatch({ type: "ADD", payload: values }); @@ -48,7 +52,7 @@ const SoundUpload = () => { return ( - {({ setFieldValue, errors, setFieldError, values }) => ( + {({ setFieldValue, errors, setFieldError }) => (