From 83de70d3d86764b2907a349689539518bac3f83d Mon Sep 17 00:00:00 2001 From: piyush06singhal Date: Tue, 3 Mar 2026 13:21:39 +0530 Subject: [PATCH 1/8] chore: ignore large models tar.gz files in backend --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 04d23fc8..78076677 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,5 @@ backend/token.json backend/service_account_key.json venv backend/Eduaid -.DS_Store \ No newline at end of file +.DS_Store +backend/s2v_reddit_2015_md.tar.gz From 0e68957f1e14b5d5470598af135a93fd310099ef Mon Sep 17 00:00:00 2001 From: piyush06singhal Date: Tue, 3 Mar 2026 14:29:34 +0530 Subject: [PATCH 2/8] feat: add quiz review and confirmation step before generation --- eduaid_web/src/App.js | 2 + eduaid_web/src/pages/Review.jsx | 193 ++++++++++++++++++++++++++++ eduaid_web/src/pages/Text_Input.jsx | 77 +++-------- 3 files changed, 212 insertions(+), 60 deletions(-) create mode 100644 eduaid_web/src/pages/Review.jsx diff --git a/eduaid_web/src/App.js b/eduaid_web/src/App.js index e9eef0a0..49717d34 100644 --- a/eduaid_web/src/App.js +++ b/eduaid_web/src/App.js @@ -3,6 +3,7 @@ import { Routes, Route, HashRouter } from "react-router-dom"; import Home from "./pages/Home"; import Question_Type from "./pages/Question_Type"; import Text_Input from "./pages/Text_Input"; +import Review from "./pages/Review"; import Output from "./pages/Output"; import Previous from "./pages/Previous"; import NotFound from "./pages/PageNotFound"; @@ -14,6 +15,7 @@ function App() { } /> } /> } /> + } /> } /> } /> } /> diff --git a/eduaid_web/src/pages/Review.jsx b/eduaid_web/src/pages/Review.jsx new file mode 100644 index 00000000..1e085b45 --- /dev/null +++ b/eduaid_web/src/pages/Review.jsx @@ -0,0 +1,193 @@ +import React, { useState, useEffect } from "react"; +import "../index.css"; +import logo_trans from "../assets/aossie_logo_transparent.png"; +import { Link, useNavigate } from "react-router-dom"; +import apiClient from "../utils/apiClient"; + +const Review = () => { + const navigate = useNavigate(); + const [loading, setLoading] = useState(false); + const [reviewData, setReviewData] = useState({ + text: "", + difficulty: "", + numQuestions: 0, + questionType: "", + useWikipedia: false, + inputSource: "Text" + }); + + useEffect(() => { + const text = localStorage.getItem("textContent") || ""; + const difficulty = localStorage.getItem("difficulty") || "Easy Difficulty"; + const numQuestions = parseInt(localStorage.getItem("numQuestions")) || 10; + const questionType = localStorage.getItem("selectedQuestionType") || ""; + const useWikipedia = localStorage.getItem("useWikipedia") === "1"; + + let inputSource = "Text"; + if (text.includes("uploaded file") || text.includes("Error uploading")) { + inputSource = "File Upload"; + } else if (text.includes("Google Doc")) { + inputSource = "Google Doc URL"; + } + + setReviewData({ + text, + difficulty, + numQuestions, + questionType, + useWikipedia, + inputSource + }); + + if (!text || !questionType) { + navigate("/input"); + } + }, [navigate]); + + const getQuestionTypeLabel = (type) => { + const types = { + get_shortq: "Short-Answer Type Questions", + get_mcq: "Multiple Choice Questions", + get_boolq: "True/False Questions", + get_problems: "All Questions" + }; + return types[type] || type; + }; + + const getEndpoint = (difficulty, questionType) => { + if (difficulty !== "Easy Difficulty") { + if (questionType === "get_shortq") { + return "get_shortq_hard"; + } else if (questionType === "get_mcq") { + return "get_mcq_hard"; + } + } + return questionType; + }; + + const handleConfirmGenerate = async () => { + setLoading(true); + const endpoint = getEndpoint(reviewData.difficulty, reviewData.questionType); + + try { + const requestData = { + input_text: reviewData.text, + max_questions: reviewData.numQuestions, + use_mediawiki: reviewData.useWikipedia ? 1 : 0, + }; + + const responseData = await apiClient.post(`/${endpoint}`, requestData); + localStorage.setItem("qaPairs", JSON.stringify(responseData)); + + const quizDetails = { + difficulty: reviewData.difficulty, + numQuestions: reviewData.numQuestions, + date: new Date().toLocaleDateString(), + qaPair: responseData, + }; + + let last5Quizzes = JSON.parse(localStorage.getItem("last5Quizzes")) || []; + last5Quizzes.push(quizDetails); + if (last5Quizzes.length > 5) { + last5Quizzes.shift(); + } + localStorage.setItem("last5Quizzes", JSON.stringify(last5Quizzes)); + + navigate("/output"); + } catch (error) { + console.error("Error:", error); + } finally { + setLoading(false); + } + }; + + return ( +
+ {loading && ( +
+
+
+ )} + +
+ +
+ logo +
+ Edu + Aid +
+
+ + +
+
Review Your Configuration
+

Please confirm the details before generating questions

+
+ +
+
+
+
Input Source
+
{reviewData.inputSource}
+
+ +
+
Question Type
+
+ {getQuestionTypeLabel(reviewData.questionType)} +
+
+ +
+
Number of Questions
+
{reviewData.numQuestions}
+
+ +
+
Difficulty Level
+
{reviewData.difficulty}
+
+ +
+
Use Wikipedia
+
+ {reviewData.useWikipedia ? "Yes" : "No"} +
+
+ + {reviewData.text && ( +
+
Content Preview
+
+ {reviewData.text.substring(0, 200)} + {reviewData.text.length > 200 && "..."} +
+
+ )} +
+ +
+ + + + +
+
+
+
+ ); +}; + +export default Review; diff --git a/eduaid_web/src/pages/Text_Input.jsx b/eduaid_web/src/pages/Text_Input.jsx index e341d331..20da1af7 100644 --- a/eduaid_web/src/pages/Text_Input.jsx +++ b/eduaid_web/src/pages/Text_Input.jsx @@ -1,11 +1,11 @@ -import React, { useState, useRef } from "react"; +import React, { useState, useRef, useEffect } from "react"; import "../index.css"; import logo_trans from "../assets/aossie_logo_transparent.png" import stars from "../assets/stars.png"; import cloud from "../assets/cloud.png"; import { FaClipboard } from "react-icons/fa"; import Switch from "react-switch"; -import { Link,useNavigate } from "react-router-dom"; +import { Link, useNavigate } from "react-router-dom"; import apiClient from "../utils/apiClient"; const Text_Input = () => { @@ -15,10 +15,21 @@ const Text_Input = () => { const [numQuestions, setNumQuestions] = useState(10); const [loading, setLoading] = useState(false); const fileInputRef = useRef(null); - const [fileContent, setFileContent] = useState(""); const [docUrl, setDocUrl] = useState(""); const [isToggleOn, setIsToggleOn] = useState(0); + useEffect(() => { + const savedText = localStorage.getItem("textContent"); + const savedDifficulty = localStorage.getItem("difficulty"); + const savedNumQuestions = localStorage.getItem("numQuestions"); + const savedWikipedia = localStorage.getItem("useWikipedia"); + + if (savedText) setText(savedText); + if (savedDifficulty) setDifficulty(savedDifficulty); + if (savedNumQuestions) setNumQuestions(parseInt(savedNumQuestions)); + if (savedWikipedia) setIsToggleOn(parseInt(savedWikipedia)); + }, []); + const toggleSwitch = () => { setIsToggleOn((isToggleOn + 1) % 2); }; @@ -48,10 +59,8 @@ const Text_Input = () => { }; const handleSaveToLocalStorage = async () => { - setLoading(true); - - // Check if a Google Doc URL is provided if (docUrl) { + setLoading(true); try { const data = await apiClient.post("/get_content", { document_url: docUrl }); setDocUrl(""); @@ -63,16 +72,11 @@ const Text_Input = () => { 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") - ); + localStorage.setItem("useWikipedia", isToggleOn.toString()); + navigate("/review"); } }; @@ -88,53 +92,6 @@ const Text_Input = () => { setNumQuestions((prev) => (prev > 0 ? prev - 1 : 0)); }; - const getEndpoint = (difficulty, questionType) => { - if (difficulty !== "Easy Difficulty") { - if (questionType === "get_shortq") { - return "get_shortq_hard"; - } else if (questionType === "get_mcq") { - return "get_mcq_hard"; - } - } - return questionType; - }; - - const sendToBackend = async (data, difficulty, questionType) => { - const endpoint = getEndpoint(difficulty, questionType); - try { - const requestData = { - input_text: data, - max_questions: numQuestions, - use_mediawiki: isToggleOn, - }; - - const responseData = await apiClient.post(`/${endpoint}`, requestData); - localStorage.setItem("qaPairs", JSON.stringify(responseData)); - - // Save quiz details to local storage - const quizDetails = { - difficulty, - numQuestions, - date: new Date().toLocaleDateString(), - qaPair: responseData, - }; - - let last5Quizzes = - JSON.parse(localStorage.getItem("last5Quizzes")) || []; - last5Quizzes.push(quizDetails); - if (last5Quizzes.length > 5) { - last5Quizzes.shift(); // Keep only the last 5 quizzes - } - localStorage.setItem("last5Quizzes", JSON.stringify(last5Quizzes)); - - navigate("/output"); - } catch (error) { - console.error("Error:", error); - } finally { - setLoading(false); - } - }; - return (
{loading && ( From 5effadd12c3ef4feb5824a39212b4039b99a2b6f Mon Sep 17 00:00:00 2001 From: piyush06singhal Date: Tue, 3 Mar 2026 15:26:44 +0530 Subject: [PATCH 3/8] fix: address CodeRabbit review comments --- eduaid_web/src/pages/Review.jsx | 54 +++++++++++++++++++++++------ eduaid_web/src/pages/Text_Input.jsx | 26 +++++++++++--- 2 files changed, 65 insertions(+), 15 deletions(-) diff --git a/eduaid_web/src/pages/Review.jsx b/eduaid_web/src/pages/Review.jsx index 1e085b45..a8de0bba 100644 --- a/eduaid_web/src/pages/Review.jsx +++ b/eduaid_web/src/pages/Review.jsx @@ -19,15 +19,19 @@ const Review = () => { useEffect(() => { const text = localStorage.getItem("textContent") || ""; const difficulty = localStorage.getItem("difficulty") || "Easy Difficulty"; - const numQuestions = parseInt(localStorage.getItem("numQuestions")) || 10; + const savedNumQuestions = localStorage.getItem("numQuestions"); + const numQuestions = savedNumQuestions !== null ? parseInt(savedNumQuestions, 10) : 10; const questionType = localStorage.getItem("selectedQuestionType") || ""; const useWikipedia = localStorage.getItem("useWikipedia") === "1"; - - let inputSource = "Text"; - if (text.includes("uploaded file") || text.includes("Error uploading")) { - inputSource = "File Upload"; - } else if (text.includes("Google Doc")) { - inputSource = "Google Doc URL"; + const savedInputSource = localStorage.getItem("inputSource"); + + let inputSource = savedInputSource || "text"; + if (!savedInputSource) { + if (text.includes("uploaded file") || text.includes("Error uploading")) { + inputSource = "file"; + } else if (text.includes("Google Doc")) { + inputSource = "url"; + } } setReviewData({ @@ -44,6 +48,15 @@ const Review = () => { } }, [navigate]); + const getInputSourceLabel = (source) => { + const labels = { + text: "Text", + file: "File Upload", + url: "Google Doc URL" + }; + return labels[source] || "Text"; + }; + const getQuestionTypeLabel = (type) => { const types = { get_shortq: "Short-Answer Type Questions", @@ -69,6 +82,13 @@ const Review = () => { setLoading(true); const endpoint = getEndpoint(reviewData.difficulty, reviewData.questionType); + const allowedEndpoints = ["get_shortq", "get_mcq", "get_boolq", "get_problems", "get_shortq_hard", "get_mcq_hard"]; + if (!allowedEndpoints.includes(endpoint)) { + console.error("Invalid endpoint:", endpoint); + setLoading(false); + return; + } + try { const requestData = { input_text: reviewData.text, @@ -86,7 +106,19 @@ const Review = () => { qaPair: responseData, }; - let last5Quizzes = JSON.parse(localStorage.getItem("last5Quizzes")) || []; + let last5Quizzes = []; + try { + const stored = localStorage.getItem("last5Quizzes"); + if (stored) { + const parsed = JSON.parse(stored); + if (Array.isArray(parsed)) { + last5Quizzes = parsed; + } + } + } catch (parseError) { + console.error("Failed to parse last5Quizzes:", parseError); + } + last5Quizzes.push(quizDetails); if (last5Quizzes.length > 5) { last5Quizzes.shift(); @@ -129,7 +161,7 @@ const Review = () => {
Input Source
-
{reviewData.inputSource}
+
{getInputSourceLabel(reviewData.inputSource)}
@@ -177,8 +209,8 @@ const Review = () => { onClick={handleConfirmGenerate} disabled={loading} className={`text-white text-lg sm:text-xl px-6 py-3 rounded-xl w-full sm:w-auto ${loading - ? "bg-gray-500 cursor-not-allowed" - : "bg-gradient-to-r from-[#FF005C] via-[#7600F2] to-[#00CBE7] hover:brightness-110" + ? "bg-gray-500 cursor-not-allowed" + : "bg-gradient-to-r from-[#FF005C] via-[#7600F2] to-[#00CBE7] hover:brightness-110" }`} > {loading ? "Generating..." : "Confirm & Generate"} diff --git a/eduaid_web/src/pages/Text_Input.jsx b/eduaid_web/src/pages/Text_Input.jsx index 20da1af7..ba9f5f72 100644 --- a/eduaid_web/src/pages/Text_Input.jsx +++ b/eduaid_web/src/pages/Text_Input.jsx @@ -17,17 +17,22 @@ const Text_Input = () => { const fileInputRef = useRef(null); const [docUrl, setDocUrl] = useState(""); const [isToggleOn, setIsToggleOn] = useState(0); + const [inputSource, setInputSource] = useState("text"); useEffect(() => { const savedText = localStorage.getItem("textContent"); const savedDifficulty = localStorage.getItem("difficulty"); const savedNumQuestions = localStorage.getItem("numQuestions"); const savedWikipedia = localStorage.getItem("useWikipedia"); + const savedInputSource = localStorage.getItem("inputSource"); if (savedText) setText(savedText); if (savedDifficulty) setDifficulty(savedDifficulty); - if (savedNumQuestions) setNumQuestions(parseInt(savedNumQuestions)); - if (savedWikipedia) setIsToggleOn(parseInt(savedWikipedia)); + if (savedNumQuestions !== null) { + setNumQuestions(parseInt(savedNumQuestions, 10)); + } + if (savedWikipedia) setIsToggleOn(parseInt(savedWikipedia, 10)); + if (savedInputSource) setInputSource(savedInputSource); }, []); const toggleSwitch = () => { @@ -43,9 +48,11 @@ const Text_Input = () => { try { const data = await apiClient.postFormData("/upload", formData); setText(data.content || data.error); + setInputSource("file"); } catch (error) { console.error("Error uploading file:", error); setText("Error uploading file"); + setInputSource("file"); } } }; @@ -63,19 +70,30 @@ const Text_Input = () => { setLoading(true); try { const data = await apiClient.post("/get_content", { document_url: docUrl }); + const fetchedText = data || "Error in retrieving"; setDocUrl(""); - setText(data || "Error in retrieving"); + setText(fetchedText); + setInputSource("url"); + + localStorage.setItem("textContent", fetchedText); + localStorage.setItem("difficulty", difficulty); + localStorage.setItem("numQuestions", numQuestions.toString()); + localStorage.setItem("useWikipedia", isToggleOn.toString()); + localStorage.setItem("inputSource", "url"); + navigate("/review"); } catch (error) { console.error("Error:", error); setText("Error retrieving Google Doc content"); + setInputSource("url"); } finally { setLoading(false); } } else if (text) { localStorage.setItem("textContent", text); localStorage.setItem("difficulty", difficulty); - localStorage.setItem("numQuestions", numQuestions); + localStorage.setItem("numQuestions", numQuestions.toString()); localStorage.setItem("useWikipedia", isToggleOn.toString()); + localStorage.setItem("inputSource", inputSource); navigate("/review"); } }; From a79067f6107e3f5b9364e485bd9e02a80a88a4ce Mon Sep 17 00:00:00 2001 From: piyush06singhal Date: Tue, 3 Mar 2026 15:53:39 +0530 Subject: [PATCH 4/8] fix: add payload validation, trim inputs, prevent error persistance --- eduaid_web/src/pages/Review.jsx | 9 ++++++++- eduaid_web/src/pages/Text_Input.jsx | 28 ++++++++++++++++++---------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/eduaid_web/src/pages/Review.jsx b/eduaid_web/src/pages/Review.jsx index a8de0bba..af216901 100644 --- a/eduaid_web/src/pages/Review.jsx +++ b/eduaid_web/src/pages/Review.jsx @@ -89,9 +89,16 @@ const Review = () => { return; } + const trimmedText = reviewData.text.trim(); + if (!trimmedText || !Number.isInteger(reviewData.numQuestions) || reviewData.numQuestions <= 0) { + console.error("Invalid generation payload"); + setLoading(false); + return; + } + try { const requestData = { - input_text: reviewData.text, + input_text: trimmedText, max_questions: reviewData.numQuestions, use_mediawiki: reviewData.useWikipedia ? 1 : 0, }; diff --git a/eduaid_web/src/pages/Text_Input.jsx b/eduaid_web/src/pages/Text_Input.jsx index ba9f5f72..83817898 100644 --- a/eduaid_web/src/pages/Text_Input.jsx +++ b/eduaid_web/src/pages/Text_Input.jsx @@ -51,8 +51,6 @@ const Text_Input = () => { setInputSource("file"); } catch (error) { console.error("Error uploading file:", error); - setText("Error uploading file"); - setInputSource("file"); } } }; @@ -66,11 +64,20 @@ const Text_Input = () => { }; const handleSaveToLocalStorage = async () => { - if (docUrl) { + const trimmedUrl = docUrl.trim(); + const trimmedText = text.trim(); + + if (trimmedUrl) { setLoading(true); try { - const data = await apiClient.post("/get_content", { document_url: docUrl }); - const fetchedText = data || "Error in retrieving"; + const data = await apiClient.post("/get_content", { document_url: trimmedUrl }); + if (!data || typeof data !== "string" || !data.trim()) { + console.error("Invalid document content received"); + setLoading(false); + return; + } + + const fetchedText = data.trim(); setDocUrl(""); setText(fetchedText); setInputSource("url"); @@ -83,13 +90,11 @@ const Text_Input = () => { navigate("/review"); } catch (error) { console.error("Error:", error); - setText("Error retrieving Google Doc content"); - setInputSource("url"); } finally { setLoading(false); } - } else if (text) { - localStorage.setItem("textContent", text); + } else if (trimmedText) { + localStorage.setItem("textContent", trimmedText); localStorage.setItem("difficulty", difficulty); localStorage.setItem("numQuestions", numQuestions.toString()); localStorage.setItem("useWikipedia", isToggleOn.toString()); @@ -149,7 +154,10 @@ const Text_Input = () => { className="absolute inset-0 p-8 pt-6 bg-[#83b6cc40] text-lg sm:text-xl rounded-2xl outline-none resize-none h-full overflow-y-auto text-white caret-white" style={{ scrollbarWidth: "none", msOverflowStyle: "none" }} value={text} - onChange={(e) => setText(e.target.value)} + onChange={(e) => { + setText(e.target.value); + setInputSource("text"); + }} />
From 106a3fbf5cfa9953799deb3c619b0517234e8565 Mon Sep 17 00:00:00 2001 From: piyush06singhal Date: Tue, 3 Mar 2026 16:13:26 +0530 Subject: [PATCH 5/8] fix: harden numQuestions hydration and validate question count before review navigation --- eduaid_web/src/pages/Review.jsx | 3 ++- eduaid_web/src/pages/Text_Input.jsx | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/eduaid_web/src/pages/Review.jsx b/eduaid_web/src/pages/Review.jsx index af216901..bee9f252 100644 --- a/eduaid_web/src/pages/Review.jsx +++ b/eduaid_web/src/pages/Review.jsx @@ -20,7 +20,8 @@ const Review = () => { const text = localStorage.getItem("textContent") || ""; const difficulty = localStorage.getItem("difficulty") || "Easy Difficulty"; const savedNumQuestions = localStorage.getItem("numQuestions"); - const numQuestions = savedNumQuestions !== null ? parseInt(savedNumQuestions, 10) : 10; + const parsedNumQuestions = Number.parseInt(savedNumQuestions ?? "", 10); + const numQuestions = Number.isInteger(parsedNumQuestions) && parsedNumQuestions > 0 ? parsedNumQuestions : 10; const questionType = localStorage.getItem("selectedQuestionType") || ""; const useWikipedia = localStorage.getItem("useWikipedia") === "1"; const savedInputSource = localStorage.getItem("inputSource"); diff --git a/eduaid_web/src/pages/Text_Input.jsx b/eduaid_web/src/pages/Text_Input.jsx index 83817898..5d82ecb2 100644 --- a/eduaid_web/src/pages/Text_Input.jsx +++ b/eduaid_web/src/pages/Text_Input.jsx @@ -66,7 +66,11 @@ const Text_Input = () => { const handleSaveToLocalStorage = async () => { const trimmedUrl = docUrl.trim(); const trimmedText = text.trim(); - + const validQuestionCount = Number.isInteger(numQuestions) && numQuestions > 0; + if (!validQuestionCount) { + console.error("Number of questions must be a positive integer"); + return; + } if (trimmedUrl) { setLoading(true); try { From a37949fd02ab924a03a2e59276654c5b424d43fb Mon Sep 17 00:00:00 2001 From: piyush06singhal Date: Tue, 3 Mar 2026 16:31:14 +0530 Subject: [PATCH 6/8] fix the hydration and duplication error --- eduaid_web/src/pages/Text_Input.jsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/eduaid_web/src/pages/Text_Input.jsx b/eduaid_web/src/pages/Text_Input.jsx index 5d82ecb2..eb6ec745 100644 --- a/eduaid_web/src/pages/Text_Input.jsx +++ b/eduaid_web/src/pages/Text_Input.jsx @@ -29,7 +29,13 @@ const Text_Input = () => { if (savedText) setText(savedText); if (savedDifficulty) setDifficulty(savedDifficulty); if (savedNumQuestions !== null) { - setNumQuestions(parseInt(savedNumQuestions, 10)); + const parsedNumQuestions = Number.parseInt(savedNumQuestions, 10); + + setNumQuestions( + Number.isInteger(parsedNumQuestions) && parsedNumQuestions > 0 + ? parsedNumQuestions + : 10 + ); } if (savedWikipedia) setIsToggleOn(parseInt(savedWikipedia, 10)); if (savedInputSource) setInputSource(savedInputSource); @@ -47,8 +53,13 @@ const Text_Input = () => { try { const data = await apiClient.postFormData("/upload", formData); - setText(data.content || data.error); - setInputSource("file"); + + if (data && typeof data.content === "string" && data.content.trim()) { + setText(data.content.trim()); + setInputSource("file"); + } else { + console.error("Invalid file upload response"); + } } catch (error) { console.error("Error uploading file:", error); } From abe6b69e9f05003f4fec0955d250d277a0ca996c Mon Sep 17 00:00:00 2001 From: piyush06singhal Date: Tue, 3 Mar 2026 16:48:33 +0530 Subject: [PATCH 7/8] fix the minor UI errors --- eduaid_web/src/pages/Text_Input.jsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/eduaid_web/src/pages/Text_Input.jsx b/eduaid_web/src/pages/Text_Input.jsx index eb6ec745..14966158 100644 --- a/eduaid_web/src/pages/Text_Input.jsx +++ b/eduaid_web/src/pages/Text_Input.jsx @@ -18,6 +18,7 @@ const Text_Input = () => { const [docUrl, setDocUrl] = useState(""); const [isToggleOn, setIsToggleOn] = useState(0); const [inputSource, setInputSource] = useState("text"); + const [error, setError] = useState(""); useEffect(() => { const savedText = localStorage.getItem("textContent"); @@ -37,7 +38,13 @@ const Text_Input = () => { : 10 ); } - if (savedWikipedia) setIsToggleOn(parseInt(savedWikipedia, 10)); + if (savedWikipedia !== null) { + const normalizedWikipedia = + savedWikipedia === "1" || savedWikipedia === "true" + ? 1 + : 0; + setIsToggleOn(normalizedWikipedia); + } if (savedInputSource) setInputSource(savedInputSource); }, []); @@ -83,11 +90,12 @@ const Text_Input = () => { return; } if (trimmedUrl) { + setError(""); setLoading(true); try { const data = await apiClient.post("/get_content", { document_url: trimmedUrl }); if (!data || typeof data !== "string" || !data.trim()) { - console.error("Invalid document content received"); + setError("could not retrieve content from the provided URL."); setLoading(false); return; } @@ -105,6 +113,7 @@ const Text_Input = () => { navigate("/review"); } catch (error) { console.error("Error:", error); + setError("failed to fetch document content. Please try again.") } finally { setLoading(false); } @@ -200,6 +209,11 @@ const Text_Input = () => { value={docUrl} onChange={(e) => setDocUrl(e.target.value)} /> + {error && ( +
+ {error} +
+ )}
{/* Controls Section */} From 838f968fdf4675fa3fdb3d6388337a403ce8667c Mon Sep 17 00:00:00 2001 From: piyush06singhal Date: Tue, 3 Mar 2026 17:29:27 +0530 Subject: [PATCH 8/8] fix minor serError issues --- eduaid_web/src/pages/Text_Input.jsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eduaid_web/src/pages/Text_Input.jsx b/eduaid_web/src/pages/Text_Input.jsx index 14966158..59ed6302 100644 --- a/eduaid_web/src/pages/Text_Input.jsx +++ b/eduaid_web/src/pages/Text_Input.jsx @@ -65,10 +65,11 @@ const Text_Input = () => { setText(data.content.trim()); setInputSource("file"); } else { - console.error("Invalid file upload response"); + setError("Invalid file content received."); } } catch (error) { console.error("Error uploading file:", error); + setError("Error uploading file. Please try again."); } } }; @@ -87,6 +88,7 @@ const Text_Input = () => { const validQuestionCount = Number.isInteger(numQuestions) && numQuestions > 0; if (!validQuestionCount) { console.error("Number of questions must be a positive integer"); + setError("Number of questions must be at least 1."); return; } if (trimmedUrl) {