Skip to content

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

Merged
LeMyst merged 6 commits into
cooklang:mainfrom
LeMyst:feat/menu-editor
Sep 28, 2026
Merged

LeMyst merged 6 commits into
cooklang:mainfrom
LeMyst:feat/menu-editor

Conversation

@LeMyst

@LeMyst LeMyst commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #538. Builds on the editor toolbar from #540.

The menu file stays the source of truth: as #538 explains, the menu JSON API is lossy and there is no menu → text writer. So this adds insert helpers on top of the text editor instead of a form.

Creating a menu

  • New Menu button (secondary) next to New Recipe on the listing. It keeps the current folder, like new_recipe_url (new_menu_url on RecipesTemplate). The header row now wraps so the three controls fit at phone width.
  • NewPageQuery and NewRecipeForm take kind: recipe (the default) or menu. create_recipe picks the extension and the starter content from it, redirects to /edit/{path}.menu, and error redirects keep &kind=menu. An unknown kind gets 400 and creates nothing. Name sanitising, the path-traversal checks, create_new and CSRF are unchanged and shared by both kinds.
  • Starter content:
    ---
    title: {name}
    servings: 2
    ---
    
    == Day 1 ==
    
    Breakfast: \
    -
    
  • new.html: the title, labels, placeholder, submit button and .cook / .menu suffix follow kind, which is also sent as a hidden field.

Menu mode in the editor

edit_page sets is_menu for .menu files, and the toolbar renders data-mode="menu" with two groups on one row:

[ == Day  [date]  : Meal ▾  - @ Add recipe ]  [ @ Ingredient  -- Comment  --- Metadata ]

Cookware, Timer, Note and Section are left out in menu mode. The menu page drops cookware and timers (_ => {} in the menu builder), notes are not rendered either, and Day replaces Section. The recipe toolbar is unchanged apart from Recipe reference.

/edit/{name} without an extension redirects to the file's full name (/edit/Week.menu). The listing links menus without their extension, so the menu page's Edit button used to open the recipe toolbar.

The menu group:

Control Inserts
Day == Day N == (N = sections + 1). If the date field next to it holds a date: == Saturday (2026-03-07) ==, the format extract_date / today's-menu banner read. The date then moves on one day, ready for the next click.
Meal ▾ A menu button (ARIA menu pattern) with Breakfast / Lunch / Dinner / Snacks → Meal: \ + - on the next line.
Add recipe Opens the picker → - @./Path/Name{N%servings}

Line continuation: the new bullet goes under the meal at the cursor: it fills an empty - , joins the meal above a blank line, or goes under the current line. A meal header or bullet above it that has no \ gets one in the same transaction. A bullet inserted between two lines of the same meal carries the \ on.

Enter continues the meal. In a menu, Enter at the end of a meal header or bullet adds the \ and starts the next line with - , like a list in a Markdown editor. Enter on an empty bullet ends the meal: the bullet and the \ before it go, and a blank line follows. Without this, a hand-typed bullet after - @./Baklava{…} was joined to it and rendered as one item ("Baklava - coffee"). Elsewhere, and in recipes, Enter is unchanged; autocompletion keeps Enter while its list is open.

Why a menu button rather than a <select>: on Windows/Linux, arrowing through a closed <select> fires change, which would insert a meal on every keypress.

Recipe picker (both editors)

  • Modal dialog with a combobox + listbox (aria-activedescendant). Empty or 1-character query: the whole GET /api/recipes tree. From 2 characters: GET /api/search?q=, debounced 300 ms, like the header search.
  • .menu results and the file being edited are never offered. Paths lose .cook and gain ./.
  • Servings defaults to the menu's servings frontmatter; left empty it inserts {}.
  • Keyboard: ↑/↓, Enter, Esc (focus goes back to the button); Tab stays inside the dialog.
  • In the recipe editor, a Recipe reference button opens the same picker (no servings field) and inserts @./Path/Name{} inline, cursor in the braces.

Fix: new files were not flushed before the redirect

The first CI run failed a_recipe_is_still_the_default: it read "" back right after POST /new redirected. create_recipe writes through a tokio File, which hands the bytes to a background task. Without a flush(), the redirect (and the editor loading the file) can beat the write. This predates the PR and affects recipes too. It came in with 7343753, which replaced a synchronous std::fs::write with create_new + write_all. (The commit message of ecfbc70 says tokio::fs::write; it was std::fs::write.) Fixed in ecfbc70; new_menu_test then passed 30 runs in a row locally.

i18n

All new strings are translated into every locale (second commit). Italian never received the #540 toolbar strings, so its toolbar is still half English; that is left for a separate change.

Tests

  • tests/new_menu_test.rs (through common::with_isolated_config):
    • kind=menu creates X.menu with the starter content and redirects to the editor, which opens in menu mode.
    • kind=recipe and no kind still create .cook files.
    • Unknown kinds (report, "", ../menu, MENU) are refused with 400 and create nothing.
    • ../../Escape stays inside the collection.
    • A symlink out of the collection is refused, and the error redirect keeps kind=menu.
    • An existing name returns to the menu form with "A menu with this name already exists".
    • The form and the listing link offer menus.
  • tests/e2e/menu-editor.spec.ts:
    • Day, with and without a date.
    • The Meal menu, by mouse and keyboard.
    • Nine Add-recipe placement cases.
    • The picker: servings, {}, no menus, keyboard, focus trap.
    • Recipe reference: insert, replace the selection, excludes the recipe itself.
    • axe in light and dark, and phone width.
    • The full New Menu flow: create → Day / Meal / Add recipe → autosave → rendered as days and meals on /recipe/…menu, then the file is deleted. Every other test intercepts PUT.
  • editor-toolbar.spec.ts: the recipe toolbar now has 8 buttons.

Checked locally:

  • cargo fmt --check: clean.
  • cargo clippy --all-targets: no warnings.
  • cargo test: all suites pass, including the 7 new tests.
  • npx playwright test --project=chromium: 210 passed, 5 skipped.
  • Adding a toolbar-built menu with POST /api/shopping_list/add_menu: 200.

🤖 Generated with Claude Code

LeMyst and others added 6 commits September 28, 2026 06:51
A "New Menu" button next to "New Recipe" opens the new-file form with
`kind=menu`, which creates a `.menu` file with a first day and meal and
opens it in the editor. `kind=recipe` (or none) still makes a `.cook`
file; any other kind is refused with 400. Name sanitising, the path
checks, `create_new` and the CSRF check are shared by both kinds, and
error redirects keep the kind.

The editor toolbar gets a menu mode for `.menu` files:
- Day adds `== Day N ==`, or `== Saturday (2026-03-07) ==` when a date
  is picked (the date then moves on a day);
- Meal is a menu button listing Breakfast, Lunch, Dinner and Snacks,
  and inserts `Meal: \` with a bullet under it;
- Add recipe opens a recipe picker and inserts `- @./Path/Name{N%servings}`
  under the current meal, adding the ` \` the menu page needs to keep the
  bullet in that meal.

The picker searches `/api/search` (300 ms, 2 characters, like the header
search) and otherwise lists the `/api/recipes` tree, never menus. Its
servings field defaults to the menu's `servings`; left empty it inserts
`{}`. In the recipe editor, a Recipe reference button uses the same
picker to insert `@./Path/Name{}` inline.

Closes cooklang#538

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The new-menu form, the menu toolbar and the recipe picker, in German,
Spanish, Basque, French, Italian, Dutch and Swedish. Italian had no
editor toolbar strings yet, so only the new ones are added there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`create_recipe` wrote the starter content through a tokio `File` and
redirected as soon as `write_all` returned. A tokio `File` hands writes
to a background task, so the redirect could reach the browser, and the
editor load the file, while it was still empty. The new menu test caught
it on CI, reading `""` back right after the redirect.

The unflushed write came in with 7343753 (fix(editor): address code
review feedback for recipe creation), when `tokio::fs::write` was
replaced by `create_new` + `write_all`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The listing links menus without their extension (`/recipe/Week`), and
the menu page's Edit button keeps that path, so the editor got
`/edit/Week`. The file resolved to `Week.menu`, but the toolbar mode
came from the requested path, so the page showed the recipe toolbar.

The editor now redirects a bare name to the file's full name
(`/edit/Week.menu`, or `.cook` for a recipe). The toolbar mode, the page
title and the save, delete and picture calls then all name the file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
In menu mode the toolbar showed every recipe button next to the menu
helpers, and wrapped onto a second row at laptop width. Cookware and
timers are dropped by the menu page, notes are not rendered either, and
Day does what Section does, so a menu now gets two groups:

  [ Day  date  Meal  Add recipe ]  [ Ingredient  Comment  Metadata ]

It fits on one row at 1280 px, and takes three rows at phone width
instead of five. The recipe toolbar is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A meal only holds together while every line but the last ends with
` \`; without it, the next line is joined to the previous one. Bullets
typed by hand never got one, so

    Petit-déjeuner: \
    - @./Dessert/Baklava{2%servings}
    - @coffee{} \

rendered "Baklava - coffee" as a single item.

In a menu, Enter at the end of a meal header or bullet now works like a
list in a Markdown editor: the line gets its ` \` and the next one
starts with `- `. Enter on an empty bullet ends the meal, dropping the
bullet and the ` \` before it and leaving a blank line. Anywhere else,
and in recipes, Enter is unchanged; autocompletion still takes Enter
while its list is open.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@LeMyst
LeMyst marked this pull request as ready for review September 28, 2026 06:46
@LeMyst
LeMyst requested a review from dubadub September 28, 2026 07:24
@LeMyst

LeMyst commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator Author
image

@LeMyst
LeMyst merged commit 8acfd64 into cooklang:main Sep 28, 2026
7 checks passed
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.

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

2 participants