Skip to content

feat(ui): create and edit menus with a recipe picker #538

Closed

Description

@LeMyst

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 way new_recipe_url does (src/web/builders.rs); add a new_menu_url field to RecipesTemplate.
  • src/server/ui.rs:
    • NewPageQuery and NewRecipeForm get a kind: Option<String> field: recipe (the default) or menu.
    • create_recipe uses 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 keep kind.
  • Starter content:
    ---
    title: {name}
    servings: 2
    ---
    
    == Day 1 ==
    
    Breakfast: \
    -
    
  • templates/new.html: the title, labels and the .cook / .menu suffix depend on kind, which is also sent as a hidden field. Add i18n keys new-menu*.

Menu mode in the editor

  • edit_page sets is_menu on EditTemplate from entry.is_menu(), and edit.html renders the toolbar with data-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) and extract_date look 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}.
  • 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 the GET /api/recipes tree.
  • .menu results 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 servings frontmatter; 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, using common::with_isolated_config):
    • POST /new with kind=menu creates X.menu with the starter content and redirects to the editor.
    • kind=recipe, or no kind, still creates a .cook file.
    • An unknown kind is rejected.
    • Path traversal is still rejected.
  • 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 PUT in 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 test and npm test pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions