Sam’s recipe box has picked up a lot in this course. Its starters now live in a file, it can read Ayumi’s list, it hands Sam a backup, and Sam can watch a step’s countdown. Each piece worked on its own, in a lesson or an exercise. Now you’ll put them together into the box Sam takes into the kitchen.
In this project, you’ll load the starters with their cooking steps, give every timed step a timer, and let Sam import a backup or a friend’s list without doubling anything up. This page is the brief you’ll come back to while you build.
What Sam’s Box Should Do
The Add a recipe form, the Filter field, the Delete dialog, Clear my data, and the status line all stay as they are. So does the timed feedback from Add Timed Feedback to the Page. After each save, the status line adds Saved. and clears itself two seconds later, and the Filter field redraws the list only once Sam stops typing.
Starters from a file. The starter recipes come from data/recipes.json, as in Load a JSON File With fetch(). There are four now, with Soft-boiled eggs as the new one, and each carries a list of cooking steps. The load checks response.ok before it reads the body.
If the file can’t be loaded, the box doesn’t stop with an error in the Console. The status line names the file and what went wrong, such as Couldn't load data/recipes.json: status 404., and the form keeps working. What Sam sees then depends on the save:
- No save, or one the box can’t use: The box starts empty, without starters, and Sam’s first change saves version 3 as usual.
- A version-3 save: The box loads the recipes exactly as saved, steps included, and saves as usual without needing the file.
- A version-1 or version-2 save: The box shows the saved recipes without steps, since the steps they’d receive are in the missing file. Add and Delete still work on the page, but the box writes nothing to storage on this visit, so the old save stays as it was and the next load with the file upgrades it properly.
In that last case, Sam needs to know the changes won’t last. The status line reads Couldn't load data/recipes.json: status 404. Changes won't be saved on this visit., and after Add or Delete, the message ends without Saved. A reload shows the old save again, untouched.
Steps under each recipe. Under its row, a recipe shows each step as a line of its own. A step with minutes is a timed step.
Its line shows the step and its full time, such as Simmer: 25:00 left, and it has Start, Pause, and Cancel buttons. A step without minutes, such as Add the lentils and the stock, is only text. A recipe with no steps shows no step lines at all.
Each button’s name includes its step, such as Start Simmer, so a screen reader user can tell Simmer’s Start from Bake’s, as with the egg timer’s Start eggs. The button can show only Start and carry the full name in its aria-label. render() builds each line with createElement() and sets the step’s text with textContent, never innerHTML, since a backup or a CSV list can hold any text.
A timer for every timed step. Start begins the countdown using a deadline calculated from Date.now(). Each tick works out the time left from that deadline instead of counting ticks, so the time never drifts. A busy page or a background tab can still run a tick late. The line or the done message may then lag by a second or so, or up to a minute in a tab that’s been in the background for a while, but the time it shows is always right.