Skip to content

Add guided onboarding flow for first-time users#1

Merged
joanmarcriera merged 1 commit into
mainfrom
claude/ev-ice-buying-guide-9fah46
Jun 26, 2026
Merged

Add guided onboarding flow for first-time users#1
joanmarcriera merged 1 commit into
mainfrom
claude/ev-ice-buying-guide-9fah46

Conversation

@joanmarcriera

Copy link
Copy Markdown
Owner

Summary

Introduces a guided "Start here" onboarding overlay that helps first-time users set up a sensible car comparison through plain-language questions, without requiring car knowledge. The flow adapts based on the user's situation (keeping a car, replacing a lost one, buying next, or comparing two specific cars).

Key Changes

  • New onboarding module (js/onboarding.js): A step machine that collects answers through fixed buttons and dropdowns (no free-text inputs), then builds a comparison state object matching the existing template shape. Supports four situations with context-specific follow-up questions about mileage, charging, and budget.

  • New "replace-lost-car" template (js/templates.js): A buy-vs-buy comparison template where all scenarios carry purchasePrice (no currentValue), enabling comparisons between multiple purchase options rather than keeping vs. switching.

  • Updated asset value and cash logic (js/model.js, js/cars.js): Changed assetValue0() and upfrontCash() to key off field presence rather than role, so a bought baseline (e.g., replacing a lost car) correctly depreciates from purchase price and reports its own upfront cash instead of £0. Updated applyCarToScenario() to support an asPurchase option for baselines that represent a car to buy rather than one already owned.

  • Enhanced verdict messaging (js/app.js): Refactored renderVerdict() to use a new verdictCopy() function that generates context-aware headlines and descriptions for both "keep vs. switch" and "buy vs. buy" scenarios, with proper HTML escaping.

  • UI integration (index.html, css/styles.css): Added onboarding overlay with styled choice buttons, car selection dropdowns, and navigation controls. Integrated "Start here" button in the header and "Lost your car?" template button. Overlay is shown on clean first visits (no shared URL hash) and can be reopened via the header button.

  • First-visit detection (js/app.js): Modified initialization to open the onboarding overlay only when no shared comparison is present in the URL, preserving direct links to specific comparisons.

Notable Implementation Details

  • All user inputs are constrained to predefined options (buttons, select dropdowns) to ensure only known strings/numbers reach the DOM, preventing injection risks.
  • The onboarding state is built in the same shape as loadTemplate() returns, so the existing rendering pipeline handles it seamlessly.
  • Verdict copy intelligently adapts between scenarios: "pays for itself" for keep-vs-switch, "higher price is repaid" for buy-vs-buy, with proper cash gap reporting for replacement scenarios.
  • Escape key and skip button allow users to dismiss the overlay and access the dashboard directly.

https://claude.ai/code/session_0189Ph72ijDpwJ5GJrW9S3ui

The tool dropped every visitor straight into the expert dashboard (~15 numeric
fields per car), which is hostile to anyone without car knowledge, and it had no
honest way to compare "I've lost my car — buy an EV or another petrol/diesel?"
because the model hard-coded baseline = keep your current car.

- model.js: key assetValue0() and upfrontCash() off which value field is present
  (purchasePrice vs currentValue) rather than role === "baseline", so a pure
  buy-vs-buy comparison depreciates each option from its purchase price and reports
  each option's own upfront cash. compare() now also returns baselineUpfront so the
  verdict can show the cash gap. Kept-car scenarios are unaffected.
- onboarding.js (new): a small, no-free-text step machine. Asks the situation
  (keep / replace a lost car / buying next / compare two cars), then a few plain
  questions (how far you drive, where you'd charge, rough budget) and builds a
  loadTemplate-shaped state from the existing car presets. Shown only on a clean
  first visit; shared #c= links skip it. Reopenable via a "Start here" button; Esc
  or "Skip — I know my numbers" dismisses it.
- templates.js: new replace-lost-car template (three all-purchase scenarios).
- cars.js: applyCarToScenario gains an { asPurchase } option for bought baselines.
- app.js: wire the overlay, re-key valueField off purchasePrice, and rewrite the
  verdict to read in plain language for both keep-vs-switch and buy-vs-buy.
- styles.css: overlay styling reusing the existing design tokens.
- tests: cover field-presence asset value, bought-baseline upfront cash, the kept
  baseline regression, and compare()'s baselineUpfront. 17/17 pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0189Ph72ijDpwJ5GJrW9S3ui
@joanmarcriera joanmarcriera merged commit 5770139 into main Jun 26, 2026
1 check passed
@joanmarcriera joanmarcriera deleted the claude/ev-ice-buying-guide-9fah46 branch June 26, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants