From f855699e72d892901b457de7c6854b13294358dc Mon Sep 17 00:00:00 2001 From: gosangam Date: Sun, 18 Oct 2026 14:29:05 +0530 Subject: [PATCH] Quizzes: To do = started but unfinished; durations roll into days The To do tab now lists only quizzes you've started and not finished; untouched ones stay under All. Quiz times show hours and days (3h 20m, 2d 4h) instead of ever-growing minutes, and 59.96s no longer prints as "60.0s". Co-Authored-By: Claude Opus 5.5 --- app/(app)/quizzes/quizzes-list.tsx | 4 +++- components/quiz/quiz-result-view.tsx | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/(app)/quizzes/quizzes-list.tsx b/app/(app)/quizzes/quizzes-list.tsx index 029b2a32..670c3eaf 100644 --- a/app/(app)/quizzes/quizzes-list.tsx +++ b/app/(app)/quizzes/quizzes-list.tsx @@ -57,7 +57,9 @@ export function QuizzesList() { ? true : filter === "done" ? q.my.state === "completed" - : q.my.state !== "completed", + : // To do: started but not finished. Untouched quizzes live + // under All. + q.my.state === "in_progress", ), [list, filter], ); diff --git a/components/quiz/quiz-result-view.tsx b/components/quiz/quiz-result-view.tsx index aaf29c30..af51d9d0 100644 --- a/components/quiz/quiz-result-view.tsx +++ b/components/quiz/quiz-result-view.tsx @@ -14,10 +14,24 @@ import { RichText } from "@/lib/rich-text"; import type { QuizResult } from "@/lib/quiz"; import { cn } from "@/lib/utils"; +/** + * "8.4s" / "1m 12s" / "3h 20m" / "2d 4h". Hours past 23h 59m roll up into + * days. Mirrors fmtMs in the admin's quizzes/labels.ts. + */ export function fmtMs(ms?: number | null): string { if (ms == null) return "—"; - if (ms < 60_000) return `${(ms / 1000).toFixed(1)}s`; - return `${Math.floor(ms / 60_000)}m ${Math.round((ms % 60_000) / 1000)}s`; + // Below 59.95s: one decimal place (anything higher would print "60.0s"). + if (ms < 59_950) return `${(ms / 1000).toFixed(1)}s`; + // Whole seconds from here, so rounding can't print "1m 60s". + const total = Math.round(ms / 1000); + const d = Math.floor(total / 86_400); + const h = Math.floor((total % 86_400) / 3600); + const m = Math.floor((total % 3600) / 60); + const s = total % 60; + // The two largest units: 2d 4h · 3h 20m · 12m 5s. + if (d > 0) return `${d}d ${h}h`; + if (h > 0) return `${h}h ${m}m`; + return `${m}m ${s}s`; } export function QuizResultView({ result }: { result: QuizResult }) {