- added new sound files
- new functionality to upload files - need to get and locatate uploaded files
This commit is contained in:
@@ -4,10 +4,12 @@ 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();
|
||||
|
||||
const initialValues: SoundUploadValue = {
|
||||
name: "",
|
||||
@@ -37,10 +39,10 @@ const SoundUpload = () => {
|
||||
path: "soundSettings",
|
||||
value: updatedValues,
|
||||
});
|
||||
const responsee = await fileMutation.mutateAsync(values.soundFile);
|
||||
console.log(responsee);
|
||||
if (result.reason !== "OK") {
|
||||
toast.error("Cannot update sound settings");
|
||||
} else {
|
||||
toast.success(`${values.name} file added`);
|
||||
}
|
||||
|
||||
dispatch({ type: "ADD", payload: values });
|
||||
|
||||
@@ -10,10 +10,7 @@ type BlobFileUpload = {
|
||||
};
|
||||
};
|
||||
|
||||
export async function sendBlobFileUpload({
|
||||
file,
|
||||
opts,
|
||||
}: BlobFileUpload): Promise<string> {
|
||||
export async function sendBlobFileUpload({ file, opts }: BlobFileUpload): Promise<string> {
|
||||
if (!file) throw new Error("No file supplied");
|
||||
if (!opts?.uploadUrl) throw new Error("No URL supplied");
|
||||
|
||||
@@ -42,9 +39,7 @@ export async function sendBlobFileUpload({
|
||||
const bodyText = await resp.text();
|
||||
|
||||
if (!resp.ok) {
|
||||
throw new Error(
|
||||
`Upload failed (${resp.status} ${resp.statusText}) from ${opts.uploadUrl} — ${bodyText}`
|
||||
);
|
||||
throw new Error(`Upload failed (${resp.status} ${resp.statusText}) from ${opts.uploadUrl} — ${bodyText}`);
|
||||
}
|
||||
|
||||
return bodyText;
|
||||
@@ -54,9 +49,7 @@ export async function sendBlobFileUpload({
|
||||
}
|
||||
// In browsers, fetch throws TypeError on network-level failures
|
||||
if (err instanceof TypeError) {
|
||||
throw new Error(
|
||||
`HTTP error uploading to ${opts.uploadUrl}: ${err.message}`
|
||||
);
|
||||
throw new Error(`HTTP error uploading to ${opts.uploadUrl}: ${err.message}`);
|
||||
}
|
||||
// Todo: fix error message response
|
||||
return `Hotlist Load OK`;
|
||||
|
||||
Reference in New Issue
Block a user