Skip to content

Commit

Permalink
Discarded Loading Without Input and Added an Alert for Missing Data
Browse files Browse the repository at this point in the history
  • Loading branch information
sakina1303 committed Jan 13, 2025
1 parent e55c693 commit de615ca
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 40 deletions.
22 changes: 18 additions & 4 deletions eduaid_web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 40 additions & 36 deletions eduaid_web/src/pages/Text_Input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit de615ca

Please sign in to comment.