- added framework for playing uploaded music files. need to permanently store and retreive files
This commit is contained in:
@@ -3,9 +3,12 @@ import FormGroup from "../components/FormGroup";
|
||||
import type { SoundUploadValue } from "../../../types/types";
|
||||
import { useSoundContext } from "../../../context/SoundContext";
|
||||
import { toast } from "sonner";
|
||||
import { useCameraBlackboard } from "../../../hooks/useCameraBlackboard";
|
||||
|
||||
const SoundUpload = () => {
|
||||
const { dispatch } = useSoundContext();
|
||||
const { state, dispatch } = useSoundContext();
|
||||
const { mutation } = useCameraBlackboard();
|
||||
|
||||
const initialValues: SoundUploadValue = {
|
||||
name: "",
|
||||
soundFile: null,
|
||||
@@ -13,14 +16,34 @@ const SoundUpload = () => {
|
||||
soundUrl: "",
|
||||
};
|
||||
|
||||
const handleSubmit = (values: SoundUploadValue) => {
|
||||
const handleSubmit = async (values: SoundUploadValue) => {
|
||||
if (!values.soundFile) {
|
||||
toast.warning("Please select an audio file");
|
||||
} else {
|
||||
dispatch({ type: "ADD", payload: values });
|
||||
|
||||
toast.success("Sound file upload successfully");
|
||||
return;
|
||||
}
|
||||
const alreadyExists = state?.soundOptions?.some((soundOption) => soundOption.name === values.name);
|
||||
if (state.soundOptions?.includes(values) || alreadyExists) {
|
||||
toast.warning("Sound already in list");
|
||||
return;
|
||||
}
|
||||
|
||||
const updatedValues = {
|
||||
...state,
|
||||
soundOptions: [...(state.soundOptions ?? []), values],
|
||||
};
|
||||
|
||||
const result = await mutation.mutateAsync({
|
||||
operation: "INSERT",
|
||||
path: "soundSettings",
|
||||
value: updatedValues,
|
||||
});
|
||||
if (result.reason !== "OK") {
|
||||
toast.error("Cannot update sound settings");
|
||||
} else {
|
||||
toast.success(`${values.name} file added`);
|
||||
}
|
||||
|
||||
dispatch({ type: "ADD", payload: values });
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user