// Extended onboarding — replaces the 3-step flow from home.jsx. // Steps: name → exam type → target band → placement diagnostic → level → prep months → daily minutes → done. // ─── Diagnostic helpers (module scope — pure, no component state) ───────── // Correct-% → rough current band. Linear 0%→4.5, 100%→9.0; a short 14-item // quiz can't resolve finer than this, so results are always snapped to the // nearest 0.5 band. function diagBandFromPct(pct) { const band = 4.5 + pct * 4.5; return Math.max(4, Math.min(9, Math.round(band * 2) / 2)); } function diagLevelFromBand(band) { if (band < 6) return 1; if (band < 7.5) return 2; return 3; } // Builds 6 vocab MCQs (2 per level) from the loaded vocab dataset — reuses // existing word/definition pairs rather than a separate content file. function pickVocabDiagnostic() { const vocab = window.VOCAB || []; const byLevel = { 1: [], 2: [], 3: [] }; for (const w of vocab) if (byLevel[w.lvl] && w.d) byLevel[w.lvl].push(w); const picks = []; [1, 2, 3].forEach(lvl => { const shuffled = [...byLevel[lvl]].sort(() => Math.random() - 0.5); picks.push(...shuffled.slice(0, 2)); }); return picks.map((word, i) => { const distractorPool = vocab.filter(w => w.d && w.w !== word.w && w.d !== word.d); const distractors = [...distractorPool].sort(() => Math.random() - 0.5).slice(0, 3).map(w => w.d); if (distractors.length < 3) return null; const options = [word.d, ...distractors].sort(() => Math.random() - 0.5); return { id: 'v' + i, word: word.w, options, correctIndex: options.indexOf(word.d) }; }).filter(Boolean); } function Onboarding({ initialName, onFinish }) { const [step, setStep] = useState(0); const [name, setName] = useState(initialName || ''); const [examType, setExamType] = useState(null); const [targetBand, setTargetBand] = useState(7); const [level, setLevel] = useState(1); const [prepMonths, setPrepMonths] = useState(3); const [dailyMinutes, setDailyMinutes] = useState(60); // ── Diagnostic (step 3) state ── const [diagPhase, setDiagPhase] = useState('intro'); // intro|vocab|grammar|writing|summary const [vocabQs] = useState(() => pickVocabDiagnostic()); const grammarQs = window.DIAGNOSTIC_GRAMMAR || []; const [qIdx, setQIdx] = useState(0); const [vocabCorrect, setVocabCorrect] = useState(0); const [grammarCorrect, setGrammarCorrect] = useState(0); const [selectedOpt, setSelectedOpt] = useState(null); const [locked, setLocked] = useState(false); const [writingText, setWritingText] = useState(''); const [writingStatus, setWritingStatus] = useState('idle'); // idle|scoring|error const [diagResult, setDiagResult] = useState(null); const startDiagnostic = () => { if (vocabQs.length > 0) setDiagPhase('vocab'); else if (grammarQs.length > 0) setDiagPhase('grammar'); else finishDiagnostic(null); }; const skipDiagnostic = () => { setDiagResult({ skipped: true }); setStep(4); }; const chooseOption = (i, correctIndex, isVocab) => { if (locked) return; setSelectedOpt(i); setLocked(true); if (i === correctIndex) { if (isVocab) setVocabCorrect(c => c + 1); else setGrammarCorrect(c => c + 1); } }; const nextQuestion = (isVocab) => { setSelectedOpt(null); setLocked(false); const list = isVocab ? vocabQs : grammarQs; if (qIdx + 1 < list.length) { setQIdx(i => i + 1); } else if (isVocab) { setQIdx(0); if (grammarQs.length > 0) setDiagPhase('grammar'); else setDiagPhase('writing'); } else { setDiagPhase('writing'); } }; const finishDiagnostic = (writingBand) => { const vocabTotal = vocabQs.length, grammarTotal = grammarQs.length; const correct = vocabCorrect + grammarCorrect; const total = vocabTotal + grammarTotal; const objectivePct = total > 0 ? correct / total : 0.5; const objectiveBand = diagBandFromPct(objectivePct); const estimatedBand = writingBand != null ? Math.round((0.6 * objectiveBand + 0.4 * writingBand) * 2) / 2 : objectiveBand; const estimatedLevel = diagLevelFromBand(estimatedBand); setDiagResult({ skipped: false, vocabCorrect, vocabTotal, grammarCorrect, grammarTotal, writingBand, estimatedBand, estimatedLevel }); setLevel(estimatedLevel); setDiagPhase('summary'); }; const submitWriting = async () => { setWritingStatus('scoring'); try { const p = window.DIAGNOSTIC_WRITING_PROMPT; const res = await window.apiClient.ai.writingScore(p.task, p.exam_type, p.prompt, writingText); finishDiagnostic(typeof res.overall_band === 'number' ? res.overall_band : null); } catch (e) { // Guests aren't authenticated yet and AI providers can be flaky — the // diagnostic must never block onboarding on this being available. setWritingStatus('error'); finishDiagnostic(null); } }; const finalize = () => { const startDate = new Date().toISOString().slice(0, 10); const profile = { examType, prepMonths, dailyMinutes, startDate, examDate: null, diagnostic: diagResult, }; const plan = window.planEngine.generate({ examType, targetBand, level, prepMonths, dailyMinutes, startDate, }); onFinish({ userName: (name || 'Learner').trim(), targetBand, level, profile, plan, onboarded: true, }); }; const totalSteps = 7; const stepLabel = `Step ${step + 1} of ${totalSteps}`; return (
V
IELTS Vocab Coach
Setting up your study plan
{/* Progress dots */}
{[...Array(totalSteps)].map((_, i) => (
))}
{stepLabel}
{step === 0 && ( <>

What should we call you?

Just a name for the dashboard.

setName(e.target.value)} placeholder="e.g. Arif" maxLength={40} />
)} {step === 1 && ( <>

Which IELTS test will you take?

Different content, different writing tasks. Pick the one you'll register for.

setExamType('academic')} title="Academic" subtitle="For university admissions and professional registration. Reading is denser; Writing Task 1 is a chart/process description." /> setExamType('general')} title="General Training" subtitle="For migration, work, and secondary education. Reading uses everyday texts; Writing Task 1 is a letter." />
)} {step === 2 && ( <>

What's your target band?

Pick the score you need. We'll adjust everything around this — vocabulary, quizzes, grammar, and mock test difficulty.

{window.SUPPORTED_BANDS.map(b => { const c = window.bandConfig.for(b); return ( ); })}
{window.bandConfig.for(targetBand).blurb}
)} {step === 3 && ( setStep(2)} onStart={startDiagnostic} onSkip={skipDiagnostic} onChoose={chooseOption} onNext={nextQuestion} onWritingChange={setWritingText} onSubmitWriting={submitWriting} onSkipWriting={() => finishDiagnostic(null)} onContinue={() => setStep(4)} /> )} {step === 4 && ( <>

Your current level?

Be honest — we'll keep adjusting as you progress.

{diagResult && !diagResult.skipped && (
Based on your placement check: ~Band {diagResult.estimatedBand} → Level {diagResult.estimatedLevel}. Adjust below if it doesn't feel right.
)}
setLevel(1)} title="Level 1 · Foundation" subtitle="Building basic academic vocabulary and grammar." /> setLevel(2)} title="Level 2 · Intermediate" subtitle="Comfortable with most exam topics; refining accuracy." /> setLevel(3)} title="Level 3 · Advanced" subtitle="Polishing precision and idiomatic range for band 7.5+." />
)} {step === 5 && ( <>

How long until your test?

We'll lay out a week-by-week plan that paces vocabulary, grammar, and mock tests.

{[ { v: 1, label: '1 month', sub: 'Sprint' }, { v: 2, label: '2 months', sub: 'Tight' }, { v: 3, label: '3 months', sub: 'Standard' }, { v: 6, label: '6 months', sub: 'Steady' }, { v: 12, label: '12 months', sub: 'Marathon' }, ].map(o => ( ))}
)} {step === 6 && ( <>

How much time per day?

We'll size the daily plan to fit. You can change this later in Settings.

{[ { v: 15, label: '15 min', sub: 'Quick' }, { v: 30, label: '30 min', sub: 'Light' }, { v: 60, label: '60 min', sub: 'Solid' }, { v: 90, label: '90 min', sub: 'Intensive' }, ].map(o => ( ))}
{/* Plan preview */}
)}
); } function DiagnosticStep({ phase, vocabQs, grammarQs, qIdx, selectedOpt, locked, writingText, writingStatus, diagResult, onBack, onStart, onSkip, onChoose, onNext, onWritingChange, onSubmitWriting, onSkipWriting, onContinue, }) { if (phase === 'intro') { return ( <>

Quick placement check

2 minutes: a few vocabulary and grammar questions, plus an optional short writing sample. We use this to set your starting level instead of just guessing — you can still adjust it afterward.

); } if (phase === 'vocab' || phase === 'grammar') { const isVocab = phase === 'vocab'; const list = isVocab ? vocabQs : grammarQs; const q = list[qIdx]; if (!q) return null; const prompt = isVocab ? `Which definition matches "${q.word}"?` : q.prompt; return (
{isVocab ? 'Vocabulary' : 'Grammar'} · {qIdx + 1}/{list.length}

{prompt}

{q.options.map((opt, i) => { const isCorrect = i === q.correctIndex; const isSelected = i === selectedOpt; let bg = 'var(--bg-elevated)', border = 'var(--line)'; if (locked) { if (isCorrect) { bg = 'var(--success-soft)'; border = 'var(--success)'; } else if (isSelected) { bg = 'var(--danger-soft)'; border = 'var(--danger)'; } } return ( ); })}
{locked && (
)}
); } if (phase === 'writing') { const p = window.DIAGNOSTIC_WRITING_PROMPT || { prompt: '' }; return ( <>
Writing (optional)

{p.prompt}

A couple of sentences is enough — this only refines the estimate.