"use client";
import { useRouter } from "next/navigation";
import React, { useEffect } from "react";
import { ArrowLeft } from "lucide-react";
import { useExamStore } from "@/stores/examStore";
import QuestionItem from "@/components/QuestionItem";
import SlidingGallery from "@/components/SlidingGallery";
import { getResultViews } from "@/lib/gallery-views";
export default function ResultsPage() {
const router = useRouter();
const { result, clearResult, setStatus, status } = useExamStore();
useEffect(() => {
const handlePopState = () => {
if (status !== "finished") {
router.replace(`/categories`);
}
};
window.addEventListener("popstate", handlePopState);
return () => {
window.removeEventListener("popstate", handlePopState);
};
}, [status, router, setStatus]);
if (!result) {
return (
);
}
const handleBackToHome = () => {
setStatus("not-started"); // ✅ reset exam flow
clearResult(); // ✅ clear stored results
router.replace("/categories"); // ✅ prevent re-entry
};
const views = getResultViews(result);
return (
You did great!
{/* Render questions with correctness */}
{result.user_questions.map((q, idx) => {
const userAnswer = result.user_answers[idx];
const correctAnswer = result.correct_answers[idx];
return (
{}}
userAnswer={userAnswer}
correctAnswer={correctAnswer}
showResults={true}
/>
{/* Optional answer feedback below the question */}
{/*
{userAnswer === null ? (
Skipped — Correct: {String.fromCharCode(65 + correctAnswer)}
) : userAnswer === correctAnswer ? (
Correct
) : (
Your Answer: {String.fromCharCode(65 + userAnswer)} |
Correct Answer: {String.fromCharCode(65 + correctAnswer)}
)}
*/}
);
})}
);
}