Repository navigation
Closed
Description
Depends on #537, which adds the editor toolbar.
Goal
Add a "New menu" button next to "New Recipe", and a menu mode of the editor toolbar with helpers for days, meals and recipe references.
Why not a form-based editor
A form-based menu editor can't be built on what exists today. The /api/menus/{path} JSON loses information: free text, comments, quantities as written (it returns computed scale factors) and which items share a line. There is also no way to turn a menu model back into text. So the text file stays the source of truth, and the UI adds insert helpers on top of the text editor.
Creating a menu
templates/recipes.html: a secondary "New menu" button next to "New Recipe", linking to{prefix}/new?kind=menu. It keeps the current directory the same waynew_recipe_urldoes (src/web/builders.rs); add anew_menu_urlfield toRecipesTemplate.src/server/ui.rs:NewPageQueryandNewRecipeFormget akind: Option<String>field:recipe(the default) ormenu.create_recipeuses it to pick the extension and the starter content. Everything else stays as is: name sanitising, path traversal checks,create_new, CSRF.- On success it redirects to
/edit/{path}.menu, and error redirects keepkind.
- Starter content:
--- title: {name} servings: 2 --- == Day 1 == Breakfast: \ - templates/new.html: the title, labels and the.cook/.menusuffix depend onkind, which is also sent as a hidden field. Add i18n keysnew-menu*.
Menu mode in the editor
edit_pagesetsis_menuonEditTemplatefromentry.is_menu(), andedit.htmlrenders the toolbar withdata-mode="menu"plus an extra group:- Day: adds a new
== Day N ==block, where N is the number of existing sections plus one. An optional date input produces== Saturday (2026-03-07) ==, the format that the today's-menu banner (list_menus_for_date) andextract_datelook for. - Meal: a dropdown (Breakfast / Lunch / Dinner / Snacks) that inserts
Meal: \with-on the next line. - Add recipe: opens the recipe picker and inserts
- @./Path/Name{N%servings}.
- Day: adds a new
- Line continuation: the menu builder only groups lines into one meal when they end with
\. When a bullet is inserted under a meal header or bullet that has no trailing\, append\to that line in the same transaction.
Recipe picker (both editors)
- A modal with a search box calling
GET /api/search?q=, with the same debounce and minimum length as the header search (300 ms, 2 characters). An empty query lists recipes from theGET /api/recipestree. .menuresults are hidden. Paths lose their extension and get a./prefix, since menu references resolve from the collection root.- An optional servings field defaults to the menu's
servingsfrontmatter; leaving it empty inserts{}. - Keyboard: arrow keys, Enter and Esc, with focus kept inside the modal.
- In the recipe editor, a Recipe reference button opens the same picker and inserts
@./Path/Name{}inline, for sub-recipes.
Tests
- Rust integration test (
tests/new_menu_test.rs, usingcommon::with_isolated_config):- POST
/newwithkind=menucreatesX.menuwith the starter content and redirects to the editor. kind=recipe, or nokind, still creates a.cookfile.- An unknown
kindis rejected. - Path traversal is still rejected.
- POST
- Playwright:
- The "New menu" flow, using a unique file name and deleting the file afterwards.
- The picker inserts the right reference.
- Text added with Day and Meal renders as days and meals on the menu page.
- Intercept
PUTin every test except the creation flow.
Acceptance criteria
- A menu can be created from the UI, filled in with Day, Meal and Add recipe, and saved.
- It renders correctly on
/recipe/{name}, and "add to shopping list" works. - The recipe reference picker works in the recipe editor too.
-
cargo fmt,cargo clippy,cargo testandnpm testpass.
Metadata
Metadata
Assignees
Labels
No labels
Activity
feat(ui): Cooklang toolbar above the recipe editor
feat(ui): Cooklang toolbar above the recipe editor (#540)
feat(ui): create and edit menus with a recipe picker
feat(ui): create and edit menus with a recipe picker (cooklang#558)