diff --git a/eduaid_web/package-lock.json b/eduaid_web/package-lock.json index 265257c..4da2e59 100644 --- a/eduaid_web/package-lock.json +++ b/eduaid_web/package-lock.json @@ -11,6 +11,7 @@ "@testing-library/jest-dom": "^5.17.0", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", + "dotenv": "^16.4.7", "pdf-lib": "^1.17.1", "react": "^18.3.1", "react-dom": "^18.3.1", @@ -7136,11 +7137,15 @@ } }, "node_modules/dotenv": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", - "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==", + "version": "16.4.7", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz", + "integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==", + "license": "BSD-2-Clause", "engines": { - "node": ">=10" + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" } }, "node_modules/dotenv-expand": { @@ -15121,6 +15126,15 @@ } } }, + "node_modules/react-scripts/node_modules/dotenv": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", + "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=10" + } + }, "node_modules/react-switch": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/react-switch/-/react-switch-7.0.0.tgz", diff --git a/eduaid_web/src/pages/Text_Input.jsx b/eduaid_web/src/pages/Text_Input.jsx index 4a60753..78ac8c1 100644 --- a/eduaid_web/src/pages/Text_Input.jsx +++ b/eduaid_web/src/pages/Text_Input.jsx @@ -48,47 +48,51 @@ const Text_Input = () => { fileInputRef.current.click(); }; - const handleSaveToLocalStorage = async () => { - setLoading(true); +const handleSaveToLocalStorage = async () => { + if (!text.trim() && !fileContent.trim() && !docUrl.trim()) { + alert("Please provide input (text, file, or URL) to generate your quiz"); + return; + } - // Check if a Google Doc URL is provided - if (docUrl) { - try { - const response = await fetch(`${process.env.REACT_APP_BASE_URL}/get_content`, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ document_url: docUrl }), - }); + setLoading(true); - if (response.ok) { - const data = await response.json(); - setDocUrl(""); - setText(data || "Error in retrieving"); - } else { - console.error("Error retrieving Google Doc content"); - setText("Error retrieving Google Doc content"); - } - } catch (error) { - console.error("Error:", error); + if (docUrl) { + try { + const response = await fetch(`${process.env.REACT_APP_BASE_URL}/get_content`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ document_url: docUrl }), + }); + + if (response.ok) { + const data = await response.json(); + setDocUrl(""); + setText(data || "Error in retrieving"); + } else { + console.error("Error retrieving Google Doc content"); setText("Error retrieving Google Doc content"); - } finally { - setLoading(false); } - } else if (text) { - // Proceed with existing functionality for local storage - localStorage.setItem("textContent", text); - localStorage.setItem("difficulty", difficulty); - localStorage.setItem("numQuestions", numQuestions); - - await sendToBackend( - text, - difficulty, - localStorage.getItem("selectedQuestionType") - ); + } catch (error) { + console.error("Error:", error); + setText("Error retrieving Google Doc content"); + } finally { + setLoading(false); } - }; + } else if (text) { + localStorage.setItem("textContent", text); + localStorage.setItem("difficulty", difficulty); + localStorage.setItem("numQuestions", numQuestions); + + await sendToBackend( + text, + difficulty, + localStorage.getItem("selectedQuestionType") + ); + } +}; + const handleDifficultyChange = (e) => { setDifficulty(e.target.value);