diff --git a/src/components/component/upload.jsx b/src/components/component/upload.jsx index 700d8a4..6148dca 100644 --- a/src/components/component/upload.jsx +++ b/src/components/component/upload.jsx @@ -1,6 +1,7 @@ import { useRef } from "react"; import { useState } from "react"; import { useEffect } from "react"; +import { Toaster, toast } from "sonner"; export default function Component({ image, setImage, setImageUploaded, imageUploaded }) { @@ -27,6 +28,16 @@ export default function Component({ image, setImage, setImageUploaded, imageUplo reader.readAsDataURL(file); setImageUploaded(true); + + toast.success("Image uploaded successfully", { + action: + { + text: 'Close', + onClick: () => { + toast.dismiss(); + } + } + }); }; const handleDragOver = (e) => { @@ -35,6 +46,19 @@ export default function Component({ image, setImage, setImageUploaded, imageUplo const handleDrop = (e) => { e.preventDefault(); + // if file is not an image + if (!e.dataTransfer.files[0].type.includes('image')) { + toast.error("File type not supported", { + action: + { + label: 'Close', + onClick: () => { + toast.dismiss(); + } + } + }); + return; + } const file = e.dataTransfer.files[0]; const reader = new FileReader(); reader.onloadend = () => { @@ -44,6 +68,8 @@ export default function Component({ image, setImage, setImageUploaded, imageUplo extractColorsFromBase64(base64data); }; reader.readAsDataURL(file); + + setImageUploaded(true); }; const handleDivClick = () => { @@ -100,6 +126,7 @@ export default function Component({ image, setImage, setImageUploaded, imageUplo return (
+
) : ( -
Click to upload an Image
+
Click or Drop an Image to upload it
)}