From 8cfcb11f0af1c3c1f51757ecd6e28e857c0cf017 Mon Sep 17 00:00:00 2001 From: shafin-r Date: Sat, 7 Feb 2026 20:21:47 +0600 Subject: [PATCH] feat(error): add error handling on test screen --- src/pages/student/Practice.tsx | 5 +- src/pages/student/Rewards.tsx | 4 ++ src/pages/student/practice/Test.tsx | 81 ++++++++++++----------------- src/stores/useExamConfigStore.ts | 10 ++++ 4 files changed, 52 insertions(+), 48 deletions(-) diff --git a/src/pages/student/Practice.tsx b/src/pages/student/Practice.tsx index 52b9712..732e201 100644 --- a/src/pages/student/Practice.tsx +++ b/src/pages/student/Practice.tsx @@ -18,9 +18,12 @@ import { } from "../../components/ui/card"; import { Button } from "../../components/ui/button"; import { useNavigate } from "react-router-dom"; +import { useExamConfigStore } from "../../stores/useExamConfigStore"; export const Practice = () => { const navigate = useNavigate(); + + const userXp = useExamConfigStore.getState().userXp; return (
@@ -29,7 +32,7 @@ export const Practice = () => {
- 0 + {userXp}
diff --git a/src/pages/student/Rewards.tsx b/src/pages/student/Rewards.tsx index 55834e9..5ea3366 100644 --- a/src/pages/student/Rewards.tsx +++ b/src/pages/student/Rewards.tsx @@ -37,6 +37,7 @@ import type { Leaderboard } from "../../types/leaderboard"; import { api } from "../../utils/api"; import { Card, CardContent } from "../../components/ui/card"; import { LeaderboardRowSkeleton } from "../../components/LeaderboardSkeleton"; +import { useExamConfigStore } from "../../stores/useExamConfigStore"; export const Rewards = () => { const user = useAuthStore((state) => state.user); @@ -45,6 +46,8 @@ export const Rewards = () => { const [leaderboard, setLeaderboard] = useState(); const [loading, setLoading] = useState(false); + const { setUserXp } = useExamConfigStore(); + useEffect(() => { const fetchLeaderboard = async () => { if (!user) return; @@ -64,6 +67,7 @@ export const Rewards = () => { const response = await api.fetchLeaderboard(token); setLeaderboard(response); + setUserXp(response.user_rank.total_xp); setLoading(false); } catch (error) { setLoading(false); diff --git a/src/pages/student/practice/Test.tsx b/src/pages/student/practice/Test.tsx index 9a37229..d220802 100644 --- a/src/pages/student/practice/Test.tsx +++ b/src/pages/student/practice/Test.tsx @@ -6,7 +6,7 @@ import { CardHeader, CardTitle, } from "../../../components/ui/card"; -import { Check, Loader2 } from "lucide-react"; +import { Check, Loader2, Unplug } from "lucide-react"; import { api } from "../../../utils/api"; import { useAuthStore } from "../../../stores/authStore"; @@ -46,6 +46,7 @@ export const Test = () => { const [eliminated, setEliminated] = useState>>({}); const [showExitDialog, setShowExitDialog] = useState(false); + const [error, setError] = useState(null); useEffect(() => { if (blocker.state === "blocked") { @@ -94,6 +95,7 @@ export const Test = () => { // ✅ NOW start module phase useSatExam.getState().startExam(); } catch (error) { + setError(`Failed to start exam session: ${error}`); console.error("Failed to start exam session:", error); } }; @@ -308,6 +310,36 @@ export const Test = () => { switch (phase) { case "IDLE": + if (error) { + return ( +
+ + + + + {error} + + +
+ + +
+
+ ); + } return (
@@ -315,46 +347,6 @@ export const Test = () => { Ready to begin your test? - {/* -
-
-
- -
-
-

- {practiceSheet?.time_limit} -

-

Minutes

-
-
-
-
- -
-
-

- {practiceSheet?.questions_count} -

-

Questions

-
-
-
-
- -
-
-

- {practiceSheet?.modules.length} -

-

Modules

-
-
-
-
*/}

Before you begin:

@@ -377,12 +369,7 @@ export const Test = () => { Your progress will be saved automatically -
- - - You can take breaks using the "More" menu in the top right - -
+