Skip to content

Commit

Permalink
Added checking if a uploaded file is text one
Browse files Browse the repository at this point in the history
  • Loading branch information
sergesoroka committed Aug 9, 2024
1 parent 6386765 commit 3ca58cd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 11 additions & 2 deletions components/UploadFile/UploadFile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export default function UploadFile({
}) {
const fileQuery = `${import.meta.env.VITE_BaseURL}download?what=knnquery`;

console.log(file);

useEffect(() => {
async function fetchDate() {
const formData = new FormData();
Expand All @@ -23,8 +25,15 @@ export default function UploadFile({
const img = await response.json();
setImageData(img);
}
if (file) fetchDate();
}, [file, fileQuery, setImageData, setType]);

if (file && file.type === "text/plain") {
fetchDate();
}
if (file && file.type !== "text/plain") {
alert("Please upload a spectrum file");
setFile(null);
}
}, [file, fileQuery, setFile, setImageData, setType]);

return (
<form>
Expand Down
7 changes: 5 additions & 2 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ h1 {

.fileNameBtn {
font-size: 13px;
background-color: #c9f2ff;
background-color: light-dark(#fff, #202020);
color: light-dark(#202020, #ccc);
border: 1px solid #00ace1;
cursor: pointer;
padding: 0.4rem 0.8rem;
border-radius: 4px;
Expand All @@ -189,7 +191,8 @@ h1 {
}

.fileNameBtn:hover {
background-color: #adecff;
background-color: #00ace1;
color: #fff;
}

.closeBtn {
Expand Down

0 comments on commit 3ca58cd

Please sign in to comment.