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 <noreply@anthropic.com>
This commit is contained in:
gosangam
2026-10-18 14:29:05 +05:30
co-authored by Claude Opus 5.5
parent 52cd48b12e
commit f855699e72
2 changed files with 19 additions and 3 deletions
+3 -1
View File
@@ -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],
);
+16 -2
View File
@@ -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 }) {