Report question: skip a broken card and tell the server
A generated matching card arrived on a phone with three identical definitions (the generation guards now drop those), but there was no way to get past a bad card from inside a session. The feed chrome (deck study, review, mistakes and exam) now has the red "!" control: one tap records the question, skips to the next card and shows an Undo toast. - lib/question-reports.ts: the local list (freezmo.reports.v1, zod on read, capped 200) is the skip state — reported cards leave every session type, count as "not attempted" in the results instead of wrong, and Undo takes a report back. A deck where everything is reported stays studiable so it can be regenerated. - POST /api/reports appends one JSON line per report to REPORTS_DIR/reports.jsonl (shared/freezmo/reports in production, the dev data dir in dev). Deliberately write-only: the question text is readable on the server (that is the point — prompt tuning) but never over HTTP, since the app has no auth. Best effort: offline reports stay local. - The button: a red outlined rounded square with "!", the chrome's control size, in both feed headers (hidden on the results slide). - config: REPORTS_DIR + RATE_LIMIT_REPORTS (20); the deploy creates the shared reports dir; the dev unit and AGENTS.md note the new server data location. - Suites: phase-1 (append + validation + no GET), phase-2 (button, toast, server POST, local copy, skip counter, hidden next session, Undo, exam pool). SW -> freezmo-v38.
This commit is contained in:
parent
f202653017
commit
9cea13496a
16 changed files with 496 additions and 15 deletions
|
|
@ -11,11 +11,13 @@ import { materialiseActivities } from "@/lib/deck-ops";
|
|||
import { haptic } from "@/lib/haptics";
|
||||
import { recordAnswer } from "@/lib/history";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
import { withoutReported } from "@/lib/question-reports";
|
||||
import type { Activity, Deck } from "@/lib/schemas";
|
||||
import { recordAttempt, upsertDeck } from "@/lib/storage";
|
||||
import { useWakeLock } from "@/lib/use-wake-lock";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { BoltIcon, FlameIcon, XIcon } from "@/components/icons";
|
||||
import { ReportQuestionButton } from "@/components/ReportQuestionButton";
|
||||
import { Button, ProgressBar } from "@/components/ui";
|
||||
|
||||
import { ResultsScreen } from "./ResultsScreen";
|
||||
|
|
@ -27,7 +29,11 @@ export function StudyFeed({ deck }: { deck: Deck }) {
|
|||
/* Keep the screen awake for the whole study session (feature-detected). */
|
||||
useWakeLock(true);
|
||||
const [currentDeck, setCurrentDeck] = useState(deck);
|
||||
const [queue, setQueue] = useState<Activity[]>(deck.activities);
|
||||
// Reported questions never enter a session; a fully reported deck stays
|
||||
// studiable (withoutReported falls back to the full list).
|
||||
const [queue, setQueue] = useState<Activity[]>(() => withoutReported(deck.id, deck.activities));
|
||||
/** Ids reported during this run: skipped, so they are not "missed". */
|
||||
const [skipped, setSkipped] = useState<string[]>([]);
|
||||
const [index, setIndex] = useState(0);
|
||||
const [results, setResults] = useState<Record<string, AttemptResult>>({});
|
||||
const [xp, setXp] = useState(0);
|
||||
|
|
@ -107,7 +113,8 @@ export function StudyFeed({ deck }: { deck: Deck }) {
|
|||
recordedRef.current = true;
|
||||
const answered = Object.values(results);
|
||||
const correct = answered.filter((entry) => entry.correct).length;
|
||||
const score = total > 0 ? (correct / total) * 100 : 0;
|
||||
const attempted = Math.max(0, total - skipped.length);
|
||||
const score = attempted > 0 ? (correct / attempted) * 100 : 0;
|
||||
// Only a run with at least one answer counts. Without this, the scroll
|
||||
// anchoring shift when a regenerated deck swaps in could fire a bogus
|
||||
// 0% attempt before the feed had snapped back to the first slide.
|
||||
|
|
@ -117,7 +124,7 @@ export function StudyFeed({ deck }: { deck: Deck }) {
|
|||
void celebrate("big");
|
||||
}
|
||||
}
|
||||
}, [finished, results, total, currentDeck.id, retryMode]);
|
||||
}, [finished, results, total, skipped.length, currentDeck.id, retryMode]);
|
||||
|
||||
const handleAnswered = useCallback(
|
||||
(activity: Activity, correct: boolean, meta?: { userAnswer?: string }) => {
|
||||
|
|
@ -150,10 +157,13 @@ export function StudyFeed({ deck }: { deck: Deck }) {
|
|||
);
|
||||
|
||||
const missed = useMemo(
|
||||
() => queue.filter((activity) => !results[activity.id]?.correct),
|
||||
[queue, results],
|
||||
() => queue.filter((activity) => !skipped.includes(activity.id) && !results[activity.id]?.correct),
|
||||
[queue, results, skipped],
|
||||
);
|
||||
|
||||
/** What the results screen counts: reported cards were never attempted. */
|
||||
const attemptedTotal = Math.max(0, total - skipped.length);
|
||||
|
||||
const correctCount = useMemo(
|
||||
() => queue.filter((activity) => results[activity.id]?.correct).length,
|
||||
[queue, results],
|
||||
|
|
@ -163,6 +173,7 @@ export function StudyFeed({ deck }: { deck: Deck }) {
|
|||
(activities: Activity[], retry: boolean) => {
|
||||
setQueue(activities);
|
||||
setResults({});
|
||||
setSkipped([]);
|
||||
setStreak(0);
|
||||
setRetryMode(retry);
|
||||
recordedRef.current = retry; // don't overwrite the best score with a retry run
|
||||
|
|
@ -267,6 +278,16 @@ export function StudyFeed({ deck }: { deck: Deck }) {
|
|||
<BoltIcon className="size-3.5" />
|
||||
{xp}
|
||||
</span>
|
||||
{!finished && queue[index] ? (
|
||||
<ReportQuestionButton
|
||||
deck={currentDeck}
|
||||
activity={queue[index]}
|
||||
onSkip={() => {
|
||||
setSkipped((current) => [...current, queue[index].id]);
|
||||
goTo(index + 1);
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center justify-between gap-2 text-[11px] font-semibold text-[var(--text-muted)]">
|
||||
|
|
@ -318,13 +339,13 @@ export function StudyFeed({ deck }: { deck: Deck }) {
|
|||
deck={currentDeck}
|
||||
xp={xp}
|
||||
bestStreak={bestStreak}
|
||||
total={total}
|
||||
total={attemptedTotal}
|
||||
correct={correctCount}
|
||||
missed={missed}
|
||||
results={results}
|
||||
retryMode={retryMode}
|
||||
onRetryMissed={() => restart(missed, true)}
|
||||
onRestart={() => restart(currentDeck.activities, false)}
|
||||
onRestart={() => restart(withoutReported(currentDeck.id, currentDeck.activities), false)}
|
||||
onRegenerate={regenerate}
|
||||
regenerating={regenerating}
|
||||
regenerateError={regenerateError}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue