@@ -94,20 +107,27 @@ function FeedbackPage() {
AI Explanation
-
LUCID MENTOR ANALYSIS
+
+ LUCID MENTOR ANALYSIS
+
{isCorrect
- ? "Great job. Your answer matches the expected reasoning. This concept works because the underlying condition is already organized in a way that supports efficient searching."
- : "Think of this like finding a name in a sorted phone book. Because the data is ordered, you can repeatedly eliminate half of the remaining items. That is why the more efficient approach depends on sorted input."}
+ ? "Great job. Your answer matches the expected reasoning."
+ : "Think of this like searching in a sorted structure. Efficient algorithms eliminate large portions quickly, which is why ordering matters."}
-
@@ -115,16 +135,15 @@ function FeedbackPage() {
Pro Tip
- Efficient searching often depends on structure. Ordered data creates
- stronger algorithmic shortcuts.
+ Efficient searching depends on structure. Ordered data allows
+ faster algorithms.
Confused?
- Our interactive visualizer can show how the algorithm narrows the
- search space.
+ Use visual explanations to better understand how the algorithm works.
diff --git a/src/pages/GenerateQuizPage.jsx b/src/pages/GenerateQuizPage.jsx
index 0256129..d74cdbf 100644
--- a/src/pages/GenerateQuizPage.jsx
+++ b/src/pages/GenerateQuizPage.jsx
@@ -11,7 +11,7 @@ function GenerateQuizPage() {
const [error, setError] = useState("");
const [errors, setErrors] = useState({});
- const API_URL = "http://localhost:5000/generate";
+ const API_URL = "http://localhost:5000/api/quiz/generate";
const validateForm = () => {
const newErrors = {};
diff --git a/src/pages/QuizPage.jsx b/src/pages/QuizPage.jsx
index 0d369a9..3c19346 100644
--- a/src/pages/QuizPage.jsx
+++ b/src/pages/QuizPage.jsx
@@ -7,9 +7,12 @@ function QuizPage() {
const questions = location.state?.questions || [];
const topic = location.state?.topic || "Data Structures & Algorithms";
+ const quizId = location.state?.quizId || null;
const [currentIndex, setCurrentIndex] = useState(0);
const [selectedAnswers, setSelectedAnswers] = useState({});
+ const [loading, setLoading] = useState(false);
+ const [error, setError] = useState("");
if (!questions.length) {
return (
@@ -35,20 +38,61 @@ function QuizPage() {
}));
};
- const handleSubmit = () => {
- const score = questions.reduce((total, question, index) => {
- return total + (selectedAnswers[index] === question.correctAnswer ? 1 : 0);
- }, 0);
-
- navigate("/feedback", {
- state: {
- topic,
- questions,
- selectedAnswers,
- score,
- currentIndex,
- },
- });
+ const handleNext = () => {
+ if (currentIndex < questions.length - 1) {
+ setCurrentIndex((prev) => prev + 1);
+ }
+ };
+
+ const handlePrevious = () => {
+ if (currentIndex > 0) {
+ setCurrentIndex((prev) => prev - 1);
+ }
+ };
+
+ const handleSubmit = async () => {
+ try {
+ setLoading(true);
+ setError("");
+
+ const answersArray = questions.map((_, index) => selectedAnswers[index] || null);
+
+ const response = await fetch("http://localhost:5000/api/quiz/submit", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ quizId,
+ questions,
+ answers: answersArray,
+ }),
+ });
+
+ const data = await response.json();
+
+ if (!response.ok) {
+ throw new Error(data.error || "Failed to submit quiz.");
+ }
+
+ navigate("/feedback", {
+ state: {
+ topic,
+ questions,
+ selectedAnswers,
+ currentIndex,
+ score: data.score,
+ total: data.total,
+ correctAnswers: data.correctAnswers,
+ wrongAnswers: data.wrongAnswers,
+ resultId: data.resultId,
+ },
+ });
+ } catch (err) {
+ setError(err.message || "Failed to submit quiz.");
+ } finally {
+ setLoading(false);
+ }
};
return (
@@ -82,7 +126,10 @@ function QuizPage() {