Skip to content

About

My solution to a React/TypeScript to-do code challenge, built with Claude Code under my direction. main: the original challenge; develop: the solution.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

This repository is my solution to a React/TypeScript to-do code challenge, built with Claude Code under my direction.

  • main holds the original challenge: the assignment README and the starting code, unchanged (view main).
  • develop (the default branch) holds the finished solution.

How to review this challenge

  1. Run it: the Run it section below.
  2. How I directed the AI, where I corrected it and what I checked myself: docs/ai-workflow.md, with diagrams of the workflow template this repo was set up from.
  3. The plan, estimates and the notes for each wave: the pinned Delivery plan issue #29.
  4. The work itself: the closed issues and merged PRs. "Direction" comments on the PRs show the instructions I gave the AI.
  5. Design choices and what's not done: the Key decisions, Known limitations and Possible improvements sections below.
  6. Time: about 6 h of work against an 8 h estimate; the table is in docs/ai-workflow.md.

To-do app

A to-do list. You can add items, tick them as done, edit their label and delete them. Open items are listed first, newest on top, and the footer counts the open and done items. Everything is saved on a small API server, so the list survives a reload.

How the work was done with AI, from task list to merged PR, is in docs/ai-workflow.md.

Run it

You need Node.js and pnpm. All commands run from the repository root.

pnpm install
What Command
API server (port 3000) pnpm -C server dev
App (port 5173) pnpm -C client dev
Storybook (port 6006) pnpm -C client dev:storybook
All checks pnpm check
Client tests pnpm -C client test
Server tests pnpm -C server test
End-to-end test pnpm e2e

The server writes to server/db.json. To try the app without changing it, use a temporary copy and another port:

cp server/db.json /tmp/todo-app-db.json
PORT=3001 DB_FILE=/tmp/todo-app-db.json pnpm -C server dev
VITE_API_URL=http://localhost:3001 pnpm -C client dev

The server reads PORT (default 3000) and DB_FILE (default server/db.json). The client reads VITE_API_URL (default http://localhost:3000), the address of the API.

The first pnpm e2e run needs the browser: pnpm exec playwright install chromium.

Tests

  • Unit and integration tests (Vitest, jsdom, Testing Library, MSW) sit next to the files they test. Pure logic such as sorting and counting has unit tests; the app, hooks and components are tested through roles, labels and text, with the network mocked by MSW.
  • Server tests (Vitest, supertest) run the API in-process on a temporary copy of db.json, never the real file.
  • The end-to-end smoke test (pnpm e2e, Playwright) runs one happy path in a real browser: add, tick, edit and delete an item. It starts its own server and client on free ports with a temporary copy of the data, and also runs in CI.
  • Stories are visual only. Hover and focus styling is checked by eye in Storybook, because jsdom does not apply CSS.
  • pnpm check runs, in order: the client type check, the type check of the client's config files, the E2E check (type check, ESLint and Prettier check of playwright.config.ts and e2e/, FIX-4 #60), then the client ESLint, the client Prettier check, and the client and server tests. It does not run pnpm e2e; CI does.
  • A failed tick or untick shows "Could not update the item." (FIX-3).

Structure

client/
  src/api/items.ts         the only code that calls the server; owns the Item type
  src/hooks/useItems.ts    loads and changes the items, keeps the state and errors
  src/items/               sortItems and countItems, pure functions with tests
  src/components/          components, each with a .module.css next to it
  src/components/form/     Form and Input
  src/components/stories/  Storybook stories
  src/App.tsx              connects the hook to the components
server/
  server.js                json-server with the "done" endpoint and createdAt
  db.json                  the data
e2e/                       Playwright test
docs/ai-workflow.md        how the work moved from tasks to merged PRs

Key decisions

  • API module and data hook. api/items.ts holds every server call and the Item type; useItems is the code that uses it. Components never fetch, so they stay easy to test and to show in Storybook. The only cast of a server response lives in that module.
  • sortItems and countItems are pure functions. Open items first, then newest first; counts of open and done items. Separate files with unit tests, not logic inside the hook.
  • Show/hide state sits inside Header and ListItem. Their props can't change, so the add button/form and the edit button/form switch inside those components.
  • While editing, the form replaces the whole row, so the input gets the full width. The task only says the edit button toggles with the form, so keeping the checkbox visible was the other option.
  • isDone marks an item as done (S1). POST /items/:id/done sets isDone to true and finishedAt to the current time; unticking sets isDone back to false and clears finishedAt. This is pending the client's answer.
  • Ticking is optimistic. The checkbox changes at once; a failed request rolls it back and shows "Could not update the item.". It first rolled back silently (F5); FIX-3 added the message so every failed action tells the user.
  • The API base URL is a setting (VITE_API_URL), so the app, the E2E test and parallel dev servers can point at any server.
  • Tests use temporary data. The server reads DB_FILE, so tests and dev servers work on a copy and never change server/db.json.

Known limitations

  • Two quick toggles of the same item send overlapping requests, so a failed request can roll the checkbox back over a newer toggle.
  • After a failed add or edit the form has already closed, so the typed text is lost (the error shows and the list is unchanged).
  • A successful add clears an earlier load error, so after a failed load the list can look complete while showing only the new item.
  • On a touchscreen laptop that also has a mouse, the row actions stay hidden until hover, so a tap can press a button that isn't visible.
  • If another row is being edited when a row is deleted, focus doesn't move to a neighbouring row.
  • The E2E run's temporary data folder is left behind when a server fails to start or when Playwright only lists the tests (--list), because the teardown doesn't run then; a failed test still cleans up.

About

My solution to a React/TypeScript to-do code challenge, built with Claude Code under my direction. main: the original challenge; develop: the solution.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages