/** * src/book/components/Checkpoint.tsx * * End-of-chapter block: wraps a set of quiz items and/or challenge prompts. * Completing it (all quizzes answered correctly) marks the chapter done * in localStorage via the progress store. * * Usage in MDX: * * Run the hello-hoop program, change one number, and re-run it. * */ import { type ReactNode } from 'react'; import { markChapterDone } from '../lib/progress.ts'; interface Props { chapterId: string; children?: ReactNode; /** Called when the user clicks "Mark complete". */ onComplete?: () => void; } import { useState } from 'react'; export default function Checkpoint({ chapterId, children, onComplete }: Props) { const [done, setDone] = useState(false); const handleComplete = () => { markChapterDone(chapterId); setDone(true); onComplete?.(); }; return (
{/* Header */}
{done ? '✓ Checkpoint complete' : 'Checkpoint'}
{/* Chapter content (quiz items, challenge description) */}
{children}
{/* Mark complete button */} {!done && ( )} {done && (

Great work — this chapter is marked done in the sidebar.

)}
); }