Phase 2: learning engine — history, SRS review, mistakes, stats, exam, reminders
Answer history and schedules - Every answer is recorded (deck, activity, topic, correct/wrong, time) in a versioned IndexedDB log (freezmo-learning v1, stores answers + srs), mirrored in memory for synchronous React reads and capped at 20k answers (oldest pruned). StudyFeed records as it grades. - Light SM-2 schedule per activity: 1 day, 3 days, then interval x ease; wrong answers return in ten minutes with the ease nudged down. Review, mistakes, stats - Library 'Smart review' card: due count, mistakes count (latest answer wrong — clears itself when answered correctly), today's goal progress. Review sessions freeze their item list at start. - New /review (due across decks, ?mistakes=1 global or ?deck= per deck) built on a shared SessionFeed with the study feed's snap/keyboard mechanics, wake lock and a results slide. - New /stats: day streak, five-week calendar, accuracy per subject and per deck, weakest topics (>=3 answers), daily-goal progress. - Daily goal configurable in Settings (10/20/30/50). Exam mode - New /exam: pick decks, question count, optional timer; no hints (a NoHints context hides hint rows and the self-check escape); results with score, per-deck and per-topic breakdown; wrong answers land in the mistakes set through the normal history. Reminders (conditional) - VAPID-gated: GET/POST/DELETE /api/push and POST /api/push/test with the standard route pattern, RATE_LIMIT_PUSH, zod, auth before body. Subscriptions stored server-side as endpoint + keys only (PUSH_DIR). UI hidden entirely without keys; iOS install note; service worker push/notificationclick handlers; scripts/send-reminders.mjs for a cron/systemd timer; web-push added as the one server dependency. Verified: new phase-2 suite 42/42 (history/SRS shapes from a real study run, mistakes clearing, review session, stats math, exam timer and breakdowns, VAPID-less hidden state plus the configured subscribe/validate/test/delete path against a second instance) plus regression 74/74, mobile 52/52, wizard 80/80, declutter 116/116, animation 8/8, native 35/35, phase1 38/38, i18n 25/25. Key parity 709/709. Lint + build clean. SW freezmo-v26.
This commit is contained in:
parent
ead6bf94db
commit
e4a8e0ba01
33 changed files with 2504 additions and 47 deletions
|
|
@ -9,10 +9,13 @@ import { FolderBar } from "@/components/FolderBar";
|
|||
import { HomeworkCard } from "@/components/HomeworkCard";
|
||||
import { FolderIcon, UploadIcon } from "@/components/icons";
|
||||
import { SegmentedPill } from "@/components/SegmentedPill";
|
||||
import { Button, EmptyState } from "@/components/ui";
|
||||
import { Button, EmptyState, ProgressBar } from "@/components/ui";
|
||||
import { folderStore, renameFolder } from "@/lib/folders";
|
||||
import { deleteHomework, homeworkStore, sortHomework } from "@/lib/homework";
|
||||
import { learningStore } from "@/lib/history";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
import { computeStats, dueCount, mistakeCount } from "@/lib/learning";
|
||||
import { settingsStore } from "@/lib/settings";
|
||||
import { ALL_FOLDERS, folderSelection, useSelectedFolder } from "@/lib/nav";
|
||||
import { springGentle } from "@/lib/motion";
|
||||
import { UNORGANIZED_ID, type Deck } from "@/lib/schemas";
|
||||
|
|
@ -52,6 +55,26 @@ export function LibraryScreen({ initialTab = "decks" }: { initialTab?: "decks" |
|
|||
useEffect(() => {
|
||||
setNudgeDue(backupNudgeDue(decks.length));
|
||||
}, [decks.length]);
|
||||
|
||||
/* Learning strip: SRS due count, open mistakes, today's goal. */
|
||||
const answers = useSyncExternalStore(
|
||||
learningStore.subscribe,
|
||||
learningStore.getAnswersSnapshot,
|
||||
learningStore.getServerAnswers,
|
||||
);
|
||||
const srs = useSyncExternalStore(
|
||||
learningStore.subscribe,
|
||||
learningStore.getSrsSnapshot,
|
||||
learningStore.getServerSrs,
|
||||
);
|
||||
const dailyGoal = useSyncExternalStore(
|
||||
settingsStore.subscribe,
|
||||
() => settingsStore.getSnapshot().dailyGoal,
|
||||
() => 20,
|
||||
);
|
||||
const due = useMemo(() => dueCount(srs), [srs]);
|
||||
const mistakes = useMemo(() => mistakeCount(answers), [answers]);
|
||||
const todayCount = useMemo(() => computeStats(answers).todayCount, [answers]);
|
||||
const importRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const sorted = useMemo(() => sortDecks(decks), [decks]);
|
||||
|
|
@ -233,6 +256,47 @@ export function LibraryScreen({ initialTab = "decks" }: { initialTab?: "decks" |
|
|||
exit={isPhone ? { opacity: 0, y: -6, transition: { duration: 0.16 } } : undefined}
|
||||
transition={springGentle}
|
||||
>
|
||||
{/* learning: review due, mistakes, exam, daily goal ---------------- */}
|
||||
<section className="card mb-5 space-y-3 p-4">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<p className="text-[11px] font-semibold uppercase tracking-wide text-[var(--text-subtle)]">
|
||||
{t("review.cardTitle")}
|
||||
</p>
|
||||
<p className="text-[11.5px] font-medium text-[var(--text-muted)]">
|
||||
{t("library.learningToday", { n: todayCount, goal: dailyGoal })}
|
||||
</p>
|
||||
</div>
|
||||
<ProgressBar value={Math.min(todayCount, dailyGoal)} max={dailyGoal} label={t("stats.today")} />
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Link
|
||||
href="/review"
|
||||
aria-disabled={due === 0}
|
||||
className={cn(
|
||||
"touch-target inline-flex h-10 items-center rounded-xl px-3.5 text-[13px] font-semibold transition",
|
||||
due > 0 ? "btn-primary" : "btn-secondary pointer-events-none opacity-60",
|
||||
)}
|
||||
>
|
||||
{t("review.title")} · {plural(due, "review.due")}
|
||||
</Link>
|
||||
<Link
|
||||
href="/review?mistakes=1"
|
||||
aria-disabled={mistakes === 0}
|
||||
className={cn(
|
||||
"touch-target inline-flex h-10 items-center rounded-xl px-3.5 text-[13px] font-semibold transition",
|
||||
mistakes > 0 ? "btn-secondary" : "btn-secondary pointer-events-none opacity-60",
|
||||
)}
|
||||
>
|
||||
{t("review.mistakesTitle")} · {plural(mistakes, "review.mistakes")}
|
||||
</Link>
|
||||
<Link
|
||||
href="/exam"
|
||||
className="btn-ghost touch-target inline-flex h-10 items-center rounded-xl px-3.5 text-[13px] font-semibold transition"
|
||||
>
|
||||
{t("exam.title")}
|
||||
</Link>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* gentle backup nudge — dismissible, never blocks ---------------- */}
|
||||
{nudgeDue ? (
|
||||
<div className="mb-5 flex flex-wrap items-center gap-3 rounded-2xl border border-[var(--hairline)] bg-[var(--surface-sunken)] px-3.5 py-3">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue