Each feature here goes through one part of the Study Hub: a command, a store selector, and a component that subscribes to exactly what it shows. Work in the lab below, or in your local project, where you can add a test for each one.
npm install and npm run dev. 1. Pause or resume
Add a Pause or resume timer command to the palette: it pauses when the timer is focusing, and resumes otherwise.
npm install and npm run dev. Hint 1: the idea
An external-store command can inspect current state at the moment it runs. Hooks are only needed for rendering subscriptions.
Hint 2: a first step
A command runs outside rendering, so it can read the store directly with
timer.getState(). No hook needed.
Show one solution
In CommandPalette.jsx:
import { send, timer } from "../store/timer.js";"Pause or resume timer": () => send(timer.getState().status === "focusing" ? "PAUSE" : "RESUME"),If the timer is idle, RESUME isn't accepted, so nothing happens: the state
machine takes care of it.
2. Progress per day
Under the bar in Stats, list each day's progress: Day 1: 0 of 2, Day 2: 1 of 2, and so on.
npm install and npm run dev. Hint 1: the idea
Select state.done, the array itself, and work out the per-day counts during
render.
Hint 2: a first step
A selector that builds a new array or object, such as
(s) => topics.filter((t) => s.done.includes(t.id)), returns a different value
every time React asks. Try it: React reports The result of getSnapshot should be
cached to avoid an infinite loop.
Show one solution
In StatsPanel.jsx, after percent:
const doneIds = useStore(progress, (s) => s.done);
const days = [1, 2, 3, 4, 5, 6].map((day) => {
const ofDay = topics.filter((t) => t.day === day);
return { day, total: ofDay.length, done: ofDay.filter((t) => doneIds.includes(t.id)).length };
});and under the sessions line:
<ul>
{days.map((d) => <li key={d.day}>Day {d.day}: {d.done} of {d.total}</li>)}
</ul>s.done is the same array until progress changes, so it's safe to select.
3. Time left on the tab
While a focus session runs, show the time left on the tab: Focus timer
(24:58). Only the tab label should re-render each second, not App.
npm install and npm run dev. Hint 1: the idea
Write a TimeLeft component that subscribes to the timer, and render it inside
the Tab. App itself doesn't read the timer, so it doesn't re-render.
Hint 2: a first step
Return null unless the status is focusing, so the label stays Focus
timer at other times. Export clock from FocusTimer.jsx to format it.
Show one solution
In FocusTimer.jsx, add export in front of const clock. In App.jsx:
import FocusTimer, { clock } from "./timer/FocusTimer.jsx";
import { timer } from "./store/timer.js";
import { useStore } from "./store/useStore.js";
function TimeLeft() {
const remaining = useStore(timer, (s) => (s.status === "focusing" ? s.remaining : null));
return remaining === null ? null : ` (${clock(remaining)})`;
}<Tab value="timer">Focus timer<TimeLeft /></Tab>This is Day 4's lesson in a new form: put the subscription in the smallest component that shows the value.
Completion is saved in this browser only. It does not measure mastery.