Repository navigation
feat(server): add a button to copy the shopping list as plain text - #411
Conversation
Adds a "Copy" button to the shopping list page that puts the current list
on the clipboard as plain text, so it can be pasted into a notes app
without needing a Cooklang parser on the other end.
The text is grouped by aisle category: the category name on its own line,
then one bare `name qty` line per item, with a blank line between groups.
Items already ticked off are left out, and a category that empties out is
dropped with them — the copy is what's still to buy.
`navigator.clipboard` only exists on secure origins, but the server is
routinely reached over plain http from a phone on the same network, which
is exactly the case this button is for. Falls back to a hidden textarea
plus `document.execCommand('copy')` there.
Refs #380
ReviewNice, focused change — client-side only, reuses the existing aggregated payload, and the empty/all-checked/all-in-pantry edge cases are all handled consistently through Correctness
Minor / nitpicks (non-blocking)
Tests
LocalesAll seven locale files got the three new keys ( Overall: solid, well-scoped implementation. No bugs or security issues found. |
The spec asserted `eggs 3` and looked up the checkbox by `data-ingredient-name="eggs"`, but the shopping list renders the aisle's common name: aisle.conf maps `egg | eggs` and `salt | sea salt`, and the copied text reuses the same aggregated payload the page renders from. Both assertions would have failed on the first CI run. The checked-item test was worse than failing — its only assertion was a negative one (`not.toMatch(/^eggs 3$/m)`), which passed vacuously because that line never existed under any state. It now asserts the item IS in the copy before ticking it off, so the exclusion is what's actually measured. Also select an explicit range in the execCommand fallback: iOS Safari ignores `select()` on a readonly textarea.
Review: Copy shopping list to clipboard (#411)Nicely scoped change — client-side only, no new endpoints, and it reuses the payload Code quality
Bugs / edge cases
Security
Test coverage
Performance
Overall this looks solid and low-risk. Main thing I'd want before merge is confirmation that the new Playwright spec actually passes in CI, since it wasn't verified locally. |
Addresses point 2 of #380 — a plaintext, non-HTML view of the shopping list for pasting into other tools.
Points 1 and 3 of that issue (exporting the list as a
.menufile, importing one) were split off to #385 per the discussion in the thread, so this PR is scoped to the copy button only.What it does
Adds a Copy button to the shopping list sidebar. It puts the current list on the clipboard as plain text, grouped by aisle category — the category name on its own line, then one bare
name qtyline per item, with a blank line between groups:That shape is what @daviddehoog asked for in the thread — "group name from aisle.conf or item and then a new line" — so it pastes cleanly into a notes app without needing a parser on the other end.
Items already ticked off are left out, and a category that empties out is dropped with them: the copy is what's still to buy. The button hides itself when there is nothing left.
Names come out as the aisle's common names (
egg, noteggs), matching what the page already displays, because it reuses the same aggregated payload the UI renders from.Notes
displayShoppingList()already receives everything needed, so the payload is just stashed for the button to re-render as text.execCommandfallback.navigator.clipboardonly exists on secure origins, butcook serveris routinely reached over plain http from a phone on the LAN — exactly the case this button is for. A hidden-textarea +document.execCommand('copy')path covers that.shopping-copy/shopping-copied/shopping-copy-failedare translated in all seven locales.Testing
cargo fmt --check,cargo clippy --all-targetsandcargo testall pass.Verified by hand in Chrome against
cook server ./seed: clicked the button, pasted the system clipboard back into the page, and got exactly the output above. Tickingeggdroppedegg 3from the next copy; ticking everything hid the button.tests/e2e/shopping-list-copy.spec.tshave not been executed — Playwright refuses to install its browser on the macOS version I'm on, so CI will be the first real run. The behavior they assert is verified by hand as above, but the spec's own selectors and timing are not.Refs #380
🤖 Generated with Claude Code