generated from muhtadeetaron/nextjs-template
fix(ui): fix exam and result screen ui
This commit is contained in:
@ -6,6 +6,7 @@ import { ArrowLeft, HelpCircle, Clock, XCircle } from "lucide-react";
|
||||
import DestructibleAlert from "@/components/DestructibleAlert";
|
||||
import BackgroundWrapper from "@/components/BackgroundWrapper";
|
||||
import { API_URL } from "@/lib/auth";
|
||||
import { useExam } from "@/context/ExamContext";
|
||||
|
||||
interface Metadata {
|
||||
metadata: {
|
||||
@ -19,6 +20,8 @@ interface Metadata {
|
||||
export default function PretestPage() {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const [examData, setExamData] = useState();
|
||||
const { startExam, setCurrentExam } = useExam();
|
||||
|
||||
// Get params from URL search params
|
||||
const name = searchParams.get("name") || "";
|
||||
@ -38,12 +41,14 @@ export default function PretestPage() {
|
||||
const questionResponse = await fetch(`${API_URL}/mock/${id}`, {
|
||||
method: "GET",
|
||||
});
|
||||
const data = await questionResponse.json();
|
||||
console.log(data);
|
||||
|
||||
if (!questionResponse.ok) {
|
||||
throw new Error("Failed to fetch questions");
|
||||
}
|
||||
|
||||
const fetchedMetadata: Metadata = await questionResponse.json();
|
||||
setExamData(data);
|
||||
const fetchedMetadata: Metadata = data;
|
||||
setMetadata(fetchedMetadata);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@ -171,16 +176,14 @@ export default function PretestPage() {
|
||||
</div>
|
||||
|
||||
<button
|
||||
className="fixed bottom-0 w-full bg-[#113768] h-[78px] flex justify-center items-center border border-transparent text-white font-bold text-2xl hover:bg-[#0d2a52] transition-colors"
|
||||
onClick={() => {
|
||||
if (metadata) {
|
||||
router.push(`/exam/${id}?time=${metadata.metadata.duration}`);
|
||||
} else {
|
||||
router.push("/unit");
|
||||
}
|
||||
setCurrentExam(examData); // Set exam first
|
||||
startExam(); // Then start exam
|
||||
router.push(`/exam/${id}?time=${metadata.metadata.duration}`);
|
||||
}}
|
||||
className="fixed bottom-0 w-full bg-[#113768] h-[78px] justify-center items-center flex text-white text-2xl font-bold"
|
||||
>
|
||||
{metadata ? "Start Test" : "Go Back"}
|
||||
Start Test
|
||||
</button>
|
||||
|
||||
{/* <CustomBackHandler fallbackRoute="paper" /> */}
|
||||
|
||||
Reference in New Issue
Block a user