Skip to content

feat(ui): copy a recipe's line for a hand-written menu - #605

Draft
LeMyst wants to merge 1 commit into
cooklang:mainfrom
LeMyst:feat/copy-menu-line
Draft

LeMyst wants to merge 1 commit into
cooklang:mainfrom
LeMyst:feat/copy-menu-line

Conversation

@LeMyst

@LeMyst LeMyst commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #671 (the last comment on #385).

A comment on #385 asks for a way to copy a recipe's path "in a format that could be pasted into a manually authored .menu file, such as - @./Lunch/Cheese, tomato and avocado sandwich{1%serving}". The menu editor's recipe picker (#558) covers menus written in the web editor; this is for menus written anywhere else.

What changes

A Copy for a Menu button on the recipe page copies the bullet that adds this recipe to a .menu, at the amount the page shows:

Page Copied
/recipe/Risotto (servings: 4) - @./Risotto{4%servings}
/recipe/Risotto?servings=6 - @./Risotto{6%servings}
/recipe/Breakfast/Chocolate Toast Delight (no servings) - @./Breakfast/Chocolate Toast Delight{}
…?scale=2 - @./Breakfast/Chocolate Toast Delight{2}
  • The path is written exactly as the recipe picker's referencePath writes it (./, forward slashes, no .cook), so a pasted line and a picked one look the same. The amount uses the forms util::menu_scale reads back (N%servings, a bare factor, or {}), so the menu then opens the recipe at that amount and the shopping list adds it at that amount.
  • The line is built on the server (templates::menu_line, from the page's path, scale and servings) and copied by a few lines of script, so a static site has the button too.
  • Clipboard API on secure origins; on plain http (a phone on the LAN) or file://, the execCommand('copy') fallback the shopping list's copy button already uses. A role="status" confirmation ("Menu line copied") appears under the button for 2.5 s.
  • The button sits after Cook, so on a phone it is this one that wraps to a second row, not the primary action; the confirmation is positioned under it and takes no room in the row.
  • Strings in all 9 locales; one line in docs/server.md.

Menus get no such button here: a menu inside a menu (@./Brunch.menu{}) is not followed by the shopping list today and belongs to the separate "menu as a day's meal" change.

Screenshots

Desktop, after copying Phone
desktop

Tests

  • Unit (web::templates::menu_line_tests): servings, factor and {} amounts; the path forms the picker normalises (.cook, ./, /, backslashes, commas in names); the line parses back as a reference to the same recipe with the same amount.
  • tests/build.rs: the static recipe page carries the line (- @./Breakfast/Easy Pancakes{2%servings}).
  • Playwright (tests/e2e/copy-menu-line.spec.ts, clipboard permissions granted): servings, after the stepper, a sub-folder recipe without servings at ×1 and ×2, the confirmation clearing, axe.
  • cargo fmt, cargo clippy --all-targets (also --no-default-features, no new warnings) and cargo test clean. Full chromium Playwright run: 252 passed, 5 skipped. After moving the button behind Cook, recipe-scaling.spec.ts › should send the scale when adding to shopping list failed once and passed on repeat (1 flaky out of 63 with --repeat-each=3); it registers its route after the scale navigation and does not touch this button.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RXA3hAKY9Q8hLCZGeokLPK

@dubadub

dubadub commented Oct 3, 2026

Copy link
Copy Markdown
Member

Should we start grouping buttons and maybe combine together add to shop list (I'd keep it on top as edits are less frequent), edit and copy?

@LeMyst

LeMyst commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator Author

Should we start grouping buttons and maybe combine together add to shop list (I'd keep it on top as edits are less frequent), edit and copy?

I think the grouping is important, but for this PR I think it's not needed anymore since you can easily add a link from the new edit menu.

A "Copy for a Menu" button on the recipe page puts the bullet that adds
this recipe to a `.menu` on the clipboard, at the amount the page shows:

    - @./Lunch/Soup{3%servings}   the recipe declares servings
    - @./Soup{2}                  scaled by a factor
    - @./Soup{}                   as written

The path is written as the menu editor's recipe picker writes it (`./`,
forward slashes, no `.cook`), so a pasted line and a picked one look the
same, and the amount is in the forms the menu scaling code reads back.

- The line is built on the server (`templates::menu_line`) from the page's
  path, scale and servings, and copied by a small script, so a static site
  has the button too.
- Clipboard API on secure origins, the `execCommand` fallback otherwise,
  as the shopping list's copy button does; a `role="status"` confirmation
  under the button.
- The button comes after Cook, so on a phone it is the one that wraps.
- Strings in all 9 locales; one line in docs/server.md.

Part of cooklang#385 (last comment).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RXA3hAKY9Q8hLCZGeokLPK
@LeMyst
LeMyst force-pushed the feat/copy-menu-line branch from 525e0af to 3c4686f Compare October 27, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants