Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/static error message #84

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ backend/credentials.json
backend/token.json
backend/service_account_key.json
venv
backend/Eduaid
backend/Eduaid
s2v_reddit_2015_md.tar.gz
23 changes: 23 additions & 0 deletions eduaid_web/package-lock.json

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

1 change: 1 addition & 0 deletions eduaid_web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"react-router-dom": "^6.26.0",
"react-scripts": "5.0.1",
"react-switch": "^7.0.0",
"react-toastify": "^11.0.2",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
50 changes: 41 additions & 9 deletions eduaid_web/src/pages/Text_Input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import stars from "../assets/stars.png";
import cloud from "../assets/cloud.png";
import { FaClipboard } from "react-icons/fa";
import Switch from "react-switch";
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

const Text_Input = () => {
const [text, setText] = useState("");
Expand All @@ -16,6 +18,19 @@ const Text_Input = () => {
const [docUrl, setDocUrl] = useState("");
const [isToggleOn, setIsToggleOn] = useState(0);

const notify = (message) => {
toast.error(message, {
position: "top-right",
autoClose: 3000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
theme: "dark",
});
};

const toggleSwitch = () => {
setIsToggleOn((isToggleOn + 1) % 2);
};
Expand All @@ -33,8 +48,10 @@ const Text_Input = () => {
});
const data = await response.json();
setText(data.content || data.error);
notify(data.error);
} catch (error) {
console.error("Error uploading file:", error);
notify("Error uploading file");
setText("Error uploading file");
}
}
Expand All @@ -50,8 +67,8 @@ const Text_Input = () => {

const handleSaveToLocalStorage = async () => {
setLoading(true);

// Check if a Google Doc URL is provided

if (docUrl) {
try {
const response = await fetch("http://localhost:5000/get_content", {
Expand All @@ -68,10 +85,12 @@ const Text_Input = () => {
setText(data || "Error in retrieving");
} else {
console.error("Error retrieving Google Doc content");
notify("Error retrieving Google Doc content");
setText("Error retrieving Google Doc content");
}
} catch (error) {
console.error("Error:", error);
notify("Error retrieving Google Doc content");
setText("Error retrieving Google Doc content");
} finally {
setLoading(false);
Expand Down Expand Up @@ -133,7 +152,6 @@ const Text_Input = () => {
if (response.ok) {
const responseData = await response.json();
localStorage.setItem("qaPairs", JSON.stringify(responseData));

// Save quiz details to local storage
const quizDetails = {
difficulty,
Expand All @@ -146,15 +164,17 @@ const Text_Input = () => {
JSON.parse(localStorage.getItem("last5Quizzes")) || [];
last5Quizzes.push(quizDetails);
if (last5Quizzes.length > 5) {
last5Quizzes.shift(); // Keep only the last 5 quizzes
last5Quizzes.shift();// Keep only the last 5 quizzes
}
localStorage.setItem("last5Quizzes", JSON.stringify(last5Quizzes));

window.location.href = "output";
} else {
notify("Backend request failed");
console.error("Backend request failed.");
}
} catch (error) {
notify("Error processing request");
console.error("Error:", error);
} finally {
setLoading(false);
Expand All @@ -169,9 +189,8 @@ const Text_Input = () => {
</div>
)}
<div
className={`w-full h-full bg-cust bg-opacity-50 ${
loading ? "pointer-events-none" : ""
}`}
className={`w-full h-full bg-cust bg-opacity-50 ${loading ? "pointer-events-none" : ""
}`}
>
<a href="/">
<div className="flex items-end gap-[2px]">
Expand Down Expand Up @@ -202,14 +221,15 @@ const Text_Input = () => {
<FaClipboard className="h-[24px] w-[24px]" />
</button>
<textarea
className="absolute inset-0 p-8 pt-4 bg-[#83b6cc40] text-xl rounded-2xl outline-none resize-none h-full overflow-y-auto text-white caret-white"
className="absolute inset-0 p-8 pt-2 mx-2 bg-[#83b6cc40] text-xl rounded-2xl outline-none resize-none h-full overflow-y-auto text-white caret-white"
style={{ scrollbarWidth: "none", msOverflowStyle: "none" }}
value={text}
readOnly={text === "Error uploading file" || text === "Unsupported file type or error processing file" || text === "No file part" || text === "No selected file"}
onChange={(e) => setText(e.target.value)}
/>
<style>
{`
textarea::-webkit-scrollbar {
textarea::-webkit-scrollbar {
display: none;
}
`}
Expand Down Expand Up @@ -309,8 +329,20 @@ const Text_Input = () => {
{/* </a> */}
</div>
</div>
<ToastContainer
position="top-right"
autoClose={3000}
hideProgressBar={false}
newestOnTop={false}
closeOnClick
rtl={false}
pauseOnFocusLoss
draggable
pauseOnHover
theme="dark"
/>
</div>
);
};

export default Text_Input;
export default Text_Input;
19 changes: 19 additions & 0 deletions extension/src/pages/text_input/TextInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ import cloud from "../../assets/cloud.png";
import arrow from "../../assets/arrow.png";
import { FaClipboard } from "react-icons/fa";
import Switch from "react-switch";
const notify = (message) => {
toast.error(message, {
position: "top-right",
autoClose: 3000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
theme: "dark",
});
};

function Second() {
const [text, setText] = useState("");
Expand Down Expand Up @@ -46,8 +58,10 @@ function Second() {
});
const data = await response.json();
setText(data.content || data.error);
notify(data.error);
} catch (error) {
console.error('Error uploading file:', error);
notify("Error uploading file");
setText('Error uploading file');
}
}
Expand Down Expand Up @@ -81,10 +95,12 @@ function Second() {
setText(data || "Error in retrieving");
} else {
console.error('Error retrieving Google Doc content');
notify("Error retrieving Google Doc content");
setText('Error retrieving Google Doc content');
}
} catch (error) {
console.error('Error:', error);
notify("Error retrieving Google Doc content");
setText('Error retrieving Google Doc content');
} finally {
setLoading(false);
Expand Down Expand Up @@ -167,9 +183,11 @@ function Second() {
window.location.href = "/src/pages/question/question.html";
} else {
console.error("Backend request failed.");
notify("Backend request failed");
}
} catch (error) {
console.error("Error:", error);
notify("Backend request failed");
} finally {
setLoading(false);
}
Expand Down Expand Up @@ -220,6 +238,7 @@ function Second() {
className="absolute inset-0 p-8 pt-2 bg-[#83b6cc40] text-lg rounded-xl outline-none resize-none h-full overflow-y-auto text-white caret-white"
style={{ scrollbarWidth: "none", msOverflowStyle: "none" }}
value={text}
readOnly={text === "Error uploading file" || text === "Unsupported file type or error processing file" || text === "No file part" || text === "No selected file"}
onChange={(e) => setText(e.target.value)}
/>
<style>
Expand Down