diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5c887ca..6322c6d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -260,7 +260,10 @@ under `/ai-engineer` are built from it at build time its correct option and says why. - **Lessons** (the optional *Lesson* step) are in `src/lib/ai/lessons.ts`, keyed by module id like quizzes: one small idea per screen in markdown, each - with a `choice`, `number` or `text` check that has a hint and a why. A lesson + with a `choice`, `number` or `text` check that has a hint and a why. A check + asks about a new case, not the example the screen just worked through. + Pictures (arrays as grids, broadcasting, bars, training steps) come from + `src/lib/ai/viz.ts`, dropped into the markdown on a line of their own. A lesson can name a notebook under `course/` (e.g. `00-setup/notebooks/step-1.ipynb`). The site links it to Colab and GitHub and serves it as a download from `/ai-engineer/notebooks/`. Every exercise in a notebook needs a hidden diff --git a/src/components/ai/Session.tsx b/src/components/ai/Session.tsx index fe013d1..a96760e 100644 --- a/src/components/ai/Session.tsx +++ b/src/components/ai/Session.tsx @@ -458,9 +458,18 @@ function Lesson({ s, exit, finish }: UnitProps) { return 0 } }) - const [sel, setSel] = useState(null) - const [answer, setAnswer] = useState('') - const [status, setStatus] = useState('ask') + // answered checks, by screen title, so going back shows your answer instead of asking again + const ansKey = `lesson-answers:${s.unitId}` + const [saved, setSaved] = useState>(() => { + try { + return JSON.parse(localStorage.getItem(ansKey) ?? '{}') + } catch { + return {} + } + }) + const [sel, setSel] = useState(() => saved[l.screens[idx].title]?.sel ?? null) + const [answer, setAnswer] = useState(() => saved[l.screens[idx].title]?.answer ?? '') + const [status, setStatus] = useState(() => saved[l.screens[idx].title]?.status ?? 'ask') const sc = l.screens[idx] const c = sc.check const last = idx === l.screens.length - 1 @@ -474,18 +483,28 @@ function Lesson({ s, exit, finish }: UnitProps) { }, [idx]) const go = (to: number) => { + const v = saved[l.screens[to].title] setIdx(to) - setSel(null) - setAnswer('') - setStatus('ask') + setSel(v?.sel ?? null) + setAnswer(v?.answer ?? '') + setStatus(v?.status ?? 'ask') window.scrollTo(0, 0) } + const settle = (st: LessonStatus) => { + setStatus(st) + if (st !== 'right' && st !== 'shown') return + const next = { ...saved, [sc.title]: { sel, answer, status: st } } + setSaved(next) + try { + localStorage.setItem(ansKey, JSON.stringify(next)) + } catch {} + } const check = () => { if (!c || answered || !ready) return if (isRight(c, sel, answer)) { if (status === 'ask') addXp(XP.quizCorrect) - setStatus('right') - } else setStatus(status === 'ask' ? 'hint' : 'shown') + settle('right') + } else settle(status === 'ask' ? 'hint' : 'shown') } const next = () => { if (!last) return go(idx + 1) @@ -513,18 +532,21 @@ function Lesson({ s, exit, finish }: UnitProps) { const footer = status === 'right' ? (
Correct!}> + {backBtn}
) : status === 'shown' ? (
}> + {backBtn}
) : status === 'hint' ? (