diff --git a/eduaid_web/src/pages/Text_Input.jsx b/eduaid_web/src/pages/Text_Input.jsx index f89e079d..cd0115aa 100644 --- a/eduaid_web/src/pages/Text_Input.jsx +++ b/eduaid_web/src/pages/Text_Input.jsx @@ -15,6 +15,7 @@ const Text_Input = () => { const [fileContent, setFileContent] = useState(""); const [docUrl, setDocUrl] = useState(""); const [isToggleOn, setIsToggleOn] = useState(0); + const [isDragging, setIsDragging] = useState(false); const toggleSwitch = () => { setIsToggleOn((isToggleOn + 1) % 2); @@ -161,6 +162,42 @@ const Text_Input = () => { } }; + const handleDragOver = (e) => { + e.preventDefault(); + e.stopPropagation(); + setIsDragging(true); + }; + + const handleDragLeave = (e) => { + e.preventDefault(); + e.stopPropagation(); + setIsDragging(false); + }; + + const handleDrop = async (e) => { + e.preventDefault(); + e.stopPropagation(); + setIsDragging(false); + + const file = e.dataTransfer.files[0]; + if (file) { + const formData = new FormData(); + formData.append("file", file); + + try { + const response = await fetch("http://localhost:5000/upload", { + method: "POST", + body: formData, + }); + const data = await response.json(); + setText(data.content || data.error); + } catch (error) { + console.error("Error uploading file:", error); + setText("Error uploading file"); + } + } + }; + return (