Files
heidi/lib/browser/record-answer.ts
CatoandClaude 48bb056e94 Every practice answer recorded per word and line (#422)
Per subject: how often asked, right, typed, time spent, last answered, and
the last wrong answer. Written in the one recorder (record.ts rule 5),
stored in the browser, synced as a summed progress key, shown on a word's
page in all seven languages, declared on the privacy page.


Claude-Session: https://claude.ai/code/session_019MDtmtfseicWGK2CMC2U5r

Co-authored-by: Claude <noreply@anthropic.com>
2026-12-02 00:56:33 +01:00

40 lines
1.6 KiB
TypeScript

import { NO_HISTORY } from "../domain/practice/history.ts";
import { NO_MEMORY } from "../domain/practice/memory.ts";
import { EMPTY_MODEL } from "../domain/practice/model.ts";
import { recordAnswer, type Answer } from "../domain/practice/record.ts";
import { NO_STATS } from "../domain/practice/stats.ts";
import { historyStore, memoryStore, modelStore, statsStore } from "./practice-stores.ts";
import { recordPractice } from "./streak-store.ts";
/**
* Write one answer into this browser: the one place a sitting, the warm-up
* and the test all go through. What an answer touches, and why a test answer
* touches less, is decided in `lib/domain/practice/record.ts`.
*
* Read at the call, not subscribed to: a sitting that re-rendered on its own
* writes would rebuild under the learner's hands.
*/
export function commitAnswer(
answer: Answer,
now: Date = new Date(),
/** Other questions about the same subject, so a review asked in another form moves the card that was due. */
siblings: readonly { id: string; kind: Answer["item"]["kind"] }[] = [],
): void {
const recorded = recordAnswer(
{
history: historyStore.read() ?? NO_HISTORY,
model: modelStore.read() ?? EMPTY_MODEL,
memory: memoryStore.read() ?? NO_MEMORY,
stats: statsStore.read() ?? NO_STATS,
},
answer,
now,
siblings,
);
if (recorded.history) historyStore.write(recorded.history);
if (recorded.model) modelStore.write(recorded.model);
if (recorded.memory) memoryStore.write(recorded.memory);
if (recorded.stats) statsStore.write(recorded.stats);
if (recorded.practised) recordPractice(now);
}