Close upload dialog when done and add toasts

This commit is contained in:
Nicolas Mowen 2024-11-27 10:53:11 -07:00
parent 2993b7f040
commit ce1ee0a28f

View File

@ -20,7 +20,7 @@ export default function FaceLibrary() {
// face data // face data
const { data: faceData } = useSWR("faces"); const { data: faceData, mutate: refreshFaces } = useSWR("faces");
const faces = useMemo<string[]>( const faces = useMemo<string[]>(
() => (faceData ? Object.keys(faceData) : []), () => (faceData ? Object.keys(faceData) : []),
@ -47,13 +47,36 @@ export default function FaceLibrary() {
(file: File) => { (file: File) => {
const formData = new FormData(); const formData = new FormData();
formData.append("file", file); formData.append("file", file);
axios.post(`faces/${pageToggle}`, formData, { axios
.post(`faces/${pageToggle}`, formData, {
headers: { headers: {
"Content-Type": "multipart/form-data", "Content-Type": "multipart/form-data",
}, },
})
.then((resp) => {
if (resp.status == 200) {
setUpload(false);
refreshFaces();
toast.success(
"Successfully uploaded iamge. View the file in the /exports folder.",
{ position: "top-center" },
);
}
})
.catch((error) => {
if (error.response?.data?.message) {
toast.error(
`Failed to upload image: ${error.response.data.message}`,
{ position: "top-center" },
);
} else {
toast.error(`Failed to upload image: ${error.message}`, {
position: "top-center",
});
}
}); });
}, },
[pageToggle], [pageToggle, refreshFaces],
); );
return ( return (