Skip to content

fix: use existing sections in pantry Add Item form - #297

Merged
dubadub merged 1 commit into
mainfrom
fix/pantry-add-item-section-selector
Apr 2, 2026
Merged

dubadub merged 1 commit into
mainfrom
fix/pantry-add-item-section-selector

Conversation

@dubadub

@dubadub dubadub commented Apr 2, 2026

Copy link
Copy Markdown
Member

Summary

  • When users have custom sections in their pantry.conf, the "Add Pantry Item" modal now populates the section dropdown with those actual sections instead of the hardcoded default list (freezer, fridge, pantry, spices, other)
  • Falls back to the default sections only when no sections exist yet

Fixes #293

When the user has custom sections in their pantry.conf, the Add Item
modal now shows those sections instead of the hardcoded default list.
Falls back to defaults only when no sections exist.

Fixes #293
@claude

claude Bot commented Apr 2, 2026

Copy link
Copy Markdown

Review: fix: use existing sections in pantry Add Item form

Summary: Good UX improvement — showing actual sections instead of hardcoded defaults makes the form contextually relevant. One bug to address before merging.

Bug: "general" section leaks into the dropdown

The pantry_page handler (src/server/ui.rs:1311-1329) iterates over all entries in pantry_conf.sections without filtering, so the special "general" section (used for ungrouped items — those without an explicit section header in the TOML file) is included in the sections vec passed to the template.

When the pantry has any ungrouped items, "general" will appear as a selectable option in the Add Item modal. Users who pick it would intend to add an item to a section called "general", but the serializers in src/pantry.rs:29-32 and src/server/handlers/pantry.rs:376 explicitly skip the "general" key when writing section headers. So the item would be silently moved to the top-level ungrouped area instead — a confusing mismatch.

Suggested fix: filter "general" out when building the sections list in pantry_page, or in the template with {% if section.name != "general" %}.

Design note: no way to create a new section via the UI

Once a pantry has sections, the dropdown only shows existing ones. A user wanting a brand-new section must edit pantry.conf manually. This may be intentional scope, but worth noting as a potential follow-up — e.g. a free-text "new section" input alongside the existing options.

HTML escaping

option value="{{ section.name }}" is safe — Askama auto-escapes HTML by default, so section names with special characters are handled correctly.

Verdict
The logic is sound and the UX improvement is real. Please address the "general" section appearing in the dropdown before merging.

@dubadub
dubadub merged commit 4ad0e51 into main Apr 2, 2026
4 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.

Improvement of form Add Pantry Item

1 participant