"use client"; import { useRouter } from "next/navigation"; import { useExam, useExamResults } from "@/context/ExamContext"; import { useEffect, useState } from "react"; import React from "react"; import { ArrowLeft } from "lucide-react"; import SlidingGallery from "@/components/SlidingGallery"; import QuestionItem from "@/components/QuestionItem"; import { getResultViews } from "@/lib/gallery-views"; export default function ResultsPage() { const router = useRouter(); const { clearExam, isExamCompleted, getApiResponse, currentAttempt, isHydrated, } = useExam(); 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) { return (
Loading...