diff --git a/app/exam/[id]/page.tsx b/app/exam/[id]/page.tsx
index 0845d04..aaed23c 100644
--- a/app/exam/[id]/page.tsx
+++ b/app/exam/[id]/page.tsx
@@ -1,6 +1,6 @@
"use client";
-import React, { useEffect, useCallback } from "react";
+import React, { useEffect, useCallback, useState } from "react";
import { useRouter, useSearchParams } from "next/navigation";
import Header from "@/components/Header";
import QuestionItem from "@/components/QuestionItem";
@@ -18,6 +18,8 @@ export default function ExamPage() {
useExamStore();
const { resetTimer, stopTimer } = useTimerStore();
+ const [isSubmitting, setIsSubmitting] = useState(false);
+
// Start exam + timer automatically
useEffect(() => {
if (type && test_id) {
@@ -27,7 +29,6 @@ export default function ExamPage() {
// Timer ended → auto-submit exam
submitExam(type);
router.push(`/categories/${type}s`);
- alert("Time's up! Your exam has been submitted.");
});
}
});
@@ -53,9 +54,14 @@ export default function ExamPage() {
);
}
- const handleSubmitExam = (type: string) => {
- submitExam(type);
- router.push(`/categories/${type}s`);
+ const handleSubmitExam = async (type: string) => {
+ try {
+ setIsSubmitting(true);
+ await submitExam(type);
+ router.push(`/exam/results`);
+ } finally {
+ setIsSubmitting(false);
+ }
};
return (
@@ -81,9 +87,17 @@ export default function ExamPage() {
diff --git a/app/exam/results/page.tsx b/app/exam/results/page.tsx
index 4052af5..9a0c524 100644
--- a/app/exam/results/page.tsx
+++ b/app/exam/results/page.tsx
@@ -1,122 +1,82 @@
"use client";
import { useRouter } from "next/navigation";
-import { useExam } from "@/context/ExamContext";
-import { useEffect, useState } from "react";
import React from "react";
import { ArrowLeft } from "lucide-react";
-import SlidingGallery from "@/components/SlidingGallery";
+import { useExamStore } from "@/stores/examStore";
import QuestionItem from "@/components/QuestionItem";
+import SlidingGallery from "@/components/SlidingGallery";
import { getResultViews } from "@/lib/gallery-views";
-import { Question } from "@/types/exam";
export default function ResultsPage() {
const router = useRouter();
- const {
- clearExam,
- isExamCompleted,
- getApiResponse,
- currentAttempt,
- isHydrated,
- } = useExam();
+ const { result, clearResult } = useExamStore();
- const [isLoading, setIsLoading] = useState(true);
-
- useEffect(() => {
- // Wait for hydration first
- if (!isHydrated) return;
-
- // Check if exam is completed, redirect if not
- if (!isExamCompleted() || !currentAttempt) {
- router.push("/unit");
- return;
- }
-
- // If we have exam results, we're ready to render
- if (currentAttempt?.answers) {
- setIsLoading(false);
- }
- }, [isExamCompleted, currentAttempt, isHydrated, router]);
-
- const handleBackToHome = () => {
- clearExam();
- router.push("/unit");
- };
-
- // Show loading screen while initializing or if no exam results
- if (isLoading || !currentAttempt) {
+ if (!result) {
return (
-
-
+
);
}
- const apiResponse = getApiResponse();
-
- // const timeTaken =
- // currentAttempt.endTime && currentAttempt.startTime
- // ? Math.round(
- // (currentAttempt.endTime.getTime() -
- // currentAttempt.startTime.getTime()) /
- // 1000 /
- // 60
- // )
- // : 0;
-
- const views = getResultViews(currentAttempt);
-
- // Get score-based message
- const getScoreMessage = () => {
- if (!currentAttempt.score || currentAttempt.score < 30)
- return "Try harder!";
- if (currentAttempt.score < 70) return "Getting Better";
- return "You did great!";
+ const handleBackToHome = () => {
+ clearResult();
+ router.push("/categories");
};
+ const views = getResultViews(result);
+
return (
-