Repository navigation
fix: use existing sections in pantry Add Item form - #297
Conversation
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
|
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 |
Summary
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)Fixes #293