diff --git a/components/Icons/Spinner.jsx b/components/Icons/Spinner.jsx new file mode 100644 index 0000000..3820f5c --- /dev/null +++ b/components/Icons/Spinner.jsx @@ -0,0 +1,40 @@ +export default function Spinner() { + return ( + + + + + + + + + + + + ); +} diff --git a/components/UploadFile/UploadFile.jsx b/components/UploadFile/UploadFile.jsx index 354acb4..474eece 100644 --- a/components/UploadFile/UploadFile.jsx +++ b/components/UploadFile/UploadFile.jsx @@ -1,18 +1,14 @@ /* eslint-disable react/prop-types */ import { useEffect, useState } from "react"; import Close from "../Icons/Close"; +import Spinner from "../Icons/Spinner"; // eslint-disable-next-line react/prop-types -export default function UploadFile({ - setImageData, - - setType, - file, - setFile, -}) { +export default function UploadFile({ setImageData, setType, file, setFile }) { const fileQuery = `${import.meta.env.VITE_BaseURL}download?what=knnquery`; const [isNotRightFile, setIsNotRightFile] = useState(false); + const [isLoading, setIsLoading] = useState(false); useEffect(() => { async function fetchDate() { @@ -22,52 +18,55 @@ export default function UploadFile({ method: "POST", body: formData, }); - const img = await response.json(); - setImageData(img); - } + if (response) setIsLoading(false); - if (file && file.type === "text/plain") { - fetchDate(); - setIsNotRightFile(false); + if (file && !response.ok) { + setIsNotRightFile(true); + } + + if (response.ok) { + setIsNotRightFile(false); + const img = await response.json(); + setImageData(img); + } } - if (file && file.type !== "text/plain") { - // alert("Please upload a spectrum file"); - setIsNotRightFile(true); - setFile(null); + if (file) { + fetchDate(); } - }, [file, fileQuery, setFile, setImageData, setType]); + }, [file, fileQuery, isLoading, setFile, setImageData, setType]); return (
- {file && ( + {file && !isNotRightFile && !isLoading && (
- File Name -
- {file.name} - {file && ( + <> + File Name +
+ {file.name} +
setFile(null)}>
- )} -
+
+
)} - {/* {!file || - (isNotRightFile && ( - No file selected - ))} */}
+ {!file && No file selected} {isNotRightFile && ( -
Please upload a spectrum file
+ + Please upload a spectrum file + )} + {isLoading && }
- {file && ( + {file && !isNotRightFile && (