Features in this app follow a path: describe the change as an action, handle it in the reducer (with a test), then dispatch it from a component. Work in the lab below, or in your local project, where you can add a test for each new reducer case.
npm install and npm run dev. 1. Clear Done
Add a Clear Done button to the toolbar that removes every card in Done. Disable it when Done is empty.
npm install and npm run dev. Hint 1: the idea
A new done_cleared action, handled with a filter. It needs no other fields.
Hint 2: a first step
Toolbar can call useBoardDispatch() itself. useBoardStats() already tells
it how many cards are done.
Show one solution
In boardReducer.js:
case "done_cleared":
return cards.filter((card) => card.column !== "done");In Toolbar.jsx:
import { useBoardDispatch } from "../state/BoardContext.jsx";const dispatch = useBoardDispatch();<button onClick={() => dispatch({ type: "done_cleared" })} disabled={done === 0}>Clear Done</button>2. A limit on Doing
Studying three things at once rarely works. Show Doing (3 of 3) in the heading when Doing is full, and hide the → buttons that would move a card into it.
npm install and npm run dev. Hint 1: the idea
A constant, const DOING_LIMIT = 3;, in data.js. It never changes, so it's
not state.
Hint 2: a first step
Board knows how many cards are in each column. Pass Column a flag such as
nextIsFull, and let CardItem hide its → when it's true.
Show one solution
In Board.jsx, work out whether each column's next column is full, using
all cards rather than the search results:
const doingCount = cards.filter((card) => card.column === "doing").length;<Column
column={column}
next={columns[index + 1]}
nextIsFull={columns[index + 1]?.id === "doing" && doingCount >= DOING_LIMIT}
...
/>Pass nextIsFull from Column to each CardItem, and show the move button
only when next && !nextIsFull. In Column's heading, when the column is
Doing and full, show ({cards.length} of {DOING_LIMIT}).
3. On your own: undo
Bring Day 2's undo and redo into the Study Board: wrap the board reducer with
withHistory, give BoardProvider the initializer, and add Undo and
Redo to the toolbar. This one has hints but no solution.
npm install and npm run dev. Hint 1: the idea
With history, the reducer's state is { past, present, future }. The provider
must give useCards() only present, so no component has to change.
Hint 2: a first step
The toolbar needs to know whether past or future is empty. Add a third,
small context for that, or a hook such as useHistoryStatus().
Completion is saved in this browser only. It does not measure mastery.