Skip to content

Commit 8d12860

Browse files
committed
Fix toFixed errors on undefined values
- Add null coalescing (?? 0) before all toFixed calls - Prevents 'Cannot read properties of undefined' errors - Affected files: page.tsx, progress/page.tsx, quiz/result/page.tsx, XPProgressBar, TopicCard, RecommendedCard, CoachFeedbackPanel
1 parent 954a0eb commit 8d12860

File tree

7 files changed

+10
-10
lines changed

7 files changed

+10
-10
lines changed

frontend/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ export default function Dashboard() {
451451
// AVG_SCORE
452452
</div>
453453
<div className="text-3xl font-bold">
454-
{recommendations.overall_stats.avg_score.toFixed(1)}%
454+
{(recommendations.overall_stats?.avg_score ?? 0).toFixed(1)}%
455455
</div>
456456
</div>
457457
<div className="border border-terminal-white p-4">

frontend/app/progress/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export default function ProgressDashboard() {
278278
<div className="border border-gray-700 p-4">
279279
<div className="text-gray-500 text-xs mb-2">// AVG ACCURACY</div>
280280
<div className="text-2xl font-bold">
281-
{stats?.avg_best_score.toFixed(1) || 0}%
281+
{(stats?.avg_best_score ?? 0).toFixed(1)}%
282282
</div>
283283
<div className="text-xs text-gray-500 mt-1">BEST SCORES</div>
284284
</div>
@@ -364,12 +364,12 @@ export default function ProgressDashboard() {
364364

365365
{/* Latest Score */}
366366
<div className="col-span-1 text-right text-gray-400">
367-
{topic.score.toFixed(1)}%
367+
{(topic.score ?? 0).toFixed(1)}%
368368
</div>
369369

370370
{/* Best Score */}
371371
<div className="col-span-2 text-right font-bold">
372-
{topic.best_score.toFixed(1)}%
372+
{(topic.best_score ?? 0).toFixed(1)}%
373373
</div>
374374

375375
{/* Attempts */}

frontend/app/quiz/result/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function ResultContent() {
128128

129129
{/* Score Display */}
130130
<div className="border-2 border-terminal-white p-12 mb-8 text-center">
131-
<div className="text-8xl font-bold mb-6">{score.toFixed(0)}%</div>
131+
<div className="text-8xl font-bold mb-6">{(score ?? 0).toFixed(0)}%</div>
132132
<div className="text-3xl mb-4">
133133
{correct} / {total} Correct
134134
</div>
@@ -156,7 +156,7 @@ function ResultContent() {
156156
<div className="flex justify-between">
157157
<span className="text-terminal-gray">Success Rate:</span>
158158
<span className={`font-mono ${performance.color}`}>
159-
{score.toFixed(1)}%
159+
{(score ?? 0).toFixed(1)}%
160160
</span>
161161
</div>
162162
{xpEarned !== null && (

frontend/components/CoachFeedbackPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export default function CoachFeedbackPanel({ userId }: CoachFeedbackProps) {
140140
</div>
141141
<div className="text-right ml-4">
142142
<div className="font-bold font-mono">
143-
{topic.score.toFixed(0)}%
143+
{(topic.score ?? 0).toFixed(0)}%
144144
</div>
145145
<div className="text-gray-600 text-xs">
146146
{topic.attempts} attempts

frontend/components/RecommendedCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default function RecommendedCard({
8282
<div className="border border-terminal-gray p-3">
8383
<div className="text-terminal-gray text-xs mb-1">// CURRENT_SCORE</div>
8484
<div className="text-xl font-bold">
85-
{recommendation.current_score !== null
85+
{recommendation.current_score !== null && recommendation.current_score !== undefined
8686
? `${recommendation.current_score.toFixed(1)}%`
8787
: "[NEW]"}
8888
</div>

frontend/components/TopicCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default function TopicCard({ topic, delay = 0 }: TopicCardProps) {
6464
<div
6565
className={`text-3xl font-bold ${getScoreColor(topic.avg_score)}`}
6666
>
67-
{topic.avg_score.toFixed(1)}%
67+
{(topic.avg_score ?? 0).toFixed(1)}%
6868
</div>
6969
</div>
7070

frontend/components/XPProgressBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default function XPProgressBar({
8383

8484
{/* Percentage text */}
8585
<div className="absolute inset-0 flex items-center justify-center text-xs font-bold mix-blend-difference">
86-
{xpProgress.toFixed(1)}%
86+
{(xpProgress ?? 0).toFixed(1)}%
8787
</div>
8888
</div>
8989

0 commit comments

Comments
 (0)