From 27f5ceed9c6e079a83e3e5b6bbe7c516af714fae Mon Sep 17 00:00:00 2001 From: Hivin Diyagama <49328442+SilverCrocus@users.noreply.github.com> Date: Thu, 19 Nov 2026 15:13:01 +1100 Subject: [PATCH 1/2] Keep Quick Add plate actions above the keyboard --- crates/openmacro-app/assets/main.css | 2 + crates/openmacro-app/src/components/logger.rs | 136 ++++++++++-------- 2 files changed, 79 insertions(+), 59 deletions(-) diff --git a/crates/openmacro-app/assets/main.css b/crates/openmacro-app/assets/main.css index d532124..2d7dd2e 100644 --- a/crates/openmacro-app/assets/main.css +++ b/crates/openmacro-app/assets/main.css @@ -397,6 +397,8 @@ h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); font-weight: 600; } .sheet-tabs button { border: none; background: transparent; color: var(--muted); padding: 6px 12px; } .sheet-tabs button.active { background: var(--surface-2); color: var(--text); } +/* Quick Add supplies its own scrolling fields and footer as sheet rows. */ +.quick-add-panel { display: contents; } .sheet-body { flex: 1; overflow-y: auto; padding: 12px 16px 16px; } .sheet-footer { padding: 0 16px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); } diff --git a/crates/openmacro-app/src/components/logger.rs b/crates/openmacro-app/src/components/logger.rs index b558048..9c5fdb7 100644 --- a/crates/openmacro-app/src/components/logger.rs +++ b/crates/openmacro-app/src/components/logger.rs @@ -64,11 +64,11 @@ pub fn Logger() -> Element { let count = plate.items.len(); // Set while a recipe's ingredients are on the plate for editing. let recipe_edit = (state.recipe_edit)(); - let log_text = if count == 1 { - "Log 1 item".to_string() - } else { - format!("Log {count} items") - }; + let quick_add_open = tab() == Tab::QuickAdd + && !saving_recipe() + && detail().is_none() + && item_edit().is_none() + && copying_food().is_none(); rsx! { div { class: "sheet-backdrop", @@ -172,7 +172,7 @@ pub fn Logger() -> Element { } } } - div { class: "sheet-body", + div { class: if quick_add_open { "quick-add-panel" } else { "sheet-body" }, if saving_recipe() { super::recipe::RecipeForm { items: plate.items.clone(), @@ -230,28 +230,17 @@ pub fn Logger() -> Element { super::ai_log::AiTab {} }, (None, None, Tab::QuickAdd) => rsx! { - QuickAdd {} + QuickAdd { count, editing_recipe: recipe_edit.is_some(), on_recipe: move |_| saving_recipe.set(true) } }, } } } } - if recipe_edit.is_some() && detail().is_none() && !saving_recipe() { - footer { class: "sheet-footer plate-actions", - button { onclick: move |_| state.close_plate(), "Cancel" } - button { - class: "primary", - disabled: count == 0, - onclick: move |_| saving_recipe.set(true), - "Update recipe" - } - } - } else if count > 0 && detail().is_none() && !saving_recipe() { - footer { class: "sheet-footer plate-actions", - if count > 1 { + if !quick_add_open && (count > 0 || recipe_edit.is_some()) && detail().is_none() && !saving_recipe() { + PlateActions { count, editing_recipe: recipe_edit.is_some(), on_recipe: move |_| saving_recipe.set(true), + if count > 1 && recipe_edit.is_none() { button { onclick: move |_| saving_recipe.set(true), "Save as recipe" } } - button { class: "primary", onclick: move |_| state.log_plate(), "{log_text}" } } } } @@ -259,6 +248,29 @@ pub fn Logger() -> Element { } } +#[component] +fn PlateActions( + count: usize, + editing_recipe: bool, + on_recipe: EventHandler<()>, + children: Element, +) -> Element { + let state = use_context::(); + rsx! { + footer { class: "sheet-footer plate-actions", + {children} + if editing_recipe { + button { onclick: move |_| state.close_plate(), "Cancel" } + button { class: "primary", disabled: count == 0, onclick: move |_| on_recipe.call(()), "Update recipe" } + } else { + button { class: "primary", disabled: count == 0, onclick: move |_| state.log_plate(), + if count == 1 { "Log 1 item" } else { "Log {count} items" } + } + } + } + } +} + #[component] fn PlateView(items: Vec, meal: Option, on_edit: EventHandler) -> Element { let state = use_context::(); @@ -746,7 +758,7 @@ fn parse_number(s: &str) -> Option { } #[component] -fn QuickAdd() -> Element { +fn QuickAdd(count: usize, editing_recipe: bool, on_recipe: EventHandler<()>) -> Element { let state = use_context::(); let mut name = use_signal(String::new); let kcal = use_signal(String::new); @@ -769,45 +781,51 @@ fn QuickAdd() -> Element { let hint = format!("Macros add up to {}", prefs::energy_text(macro_kcal)); rsx! { - label { class: "field", - span { "Name (optional)" } - input { - r#type: "text", - placeholder: "Quick add", - value: "{name}", - oninput: move |e| name.set(e.value()), + div { class: "sheet-body", + label { class: "field", + span { "Name (optional)" } + input { + r#type: "text", + placeholder: "Quick add", + value: "{name}", + oninput: move |e| name.set(e.value()), + } + } + div { class: "field-grid", + NumberField { label: "Energy", unit: prefs::energy_symbol(), value: kcal } + NumberField { label: "Protein", unit: "g", value: protein } + NumberField { label: "Fat", unit: "g", value: fat } + NumberField { label: "Carbs", unit: "g", value: carbs } + NumberField { label: "Alcohol", unit: "g", value: alcohol } + } + p { class: "muted pad", "{hint}" } + if count > 1 && !editing_recipe { + button { onclick: move |_| on_recipe.call(()), "Save as recipe" } } } - div { class: "field-grid", - NumberField { label: "Energy", unit: prefs::energy_symbol(), value: kcal } - NumberField { label: "Protein", unit: "g", value: protein } - NumberField { label: "Fat", unit: "g", value: fat } - NumberField { label: "Carbs", unit: "g", value: carbs } - NumberField { label: "Alcohol", unit: "g", value: alcohol } - } - p { class: "muted pad", "{hint}" } - button { - class: "primary wide", - disabled: energy.is_none(), - onclick: move |_| { - let Some(energy) = energy else { return }; - let label = name(); - state - .add_to_plate(PlateItem { - food_id: None, - name: if label.trim().is_empty() { "Quick add".into() } else { label.trim().to_string() }, - amount: "1 entry".into(), - nutrients: { - let n = NutrientProfile::from_macros(energy, p, f, c); - if a > 0.0 { n.with(Nutrient::Alcohol, a) } else { n } - }, - grams: None, - }); - for mut field in [name, kcal, protein, fat, carbs, alcohol] { - field.set(String::new()); - } - }, - "Add to plate" + PlateActions { count, editing_recipe, on_recipe, + button { + disabled: energy.is_none(), + onclick: move |_| { + let Some(energy) = energy else { return }; + let label = name(); + state + .add_to_plate(PlateItem { + food_id: None, + name: if label.trim().is_empty() { "Quick add".into() } else { label.trim().to_string() }, + amount: "1 entry".into(), + nutrients: { + let n = NutrientProfile::from_macros(energy, p, f, c); + if a > 0.0 { n.with(Nutrient::Alcohol, a) } else { n } + }, + grams: None, + }); + for mut field in [name, kcal, protein, fat, carbs, alcohol] { + field.set(String::new()); + } + }, + "Add to plate" + } } } } From d401d4da9d1bd136b817f148dc605d8ac1c04bfc Mon Sep 17 00:00:00 2001 From: Hivin Diyagama <49328442+SilverCrocus@users.noreply.github.com> Date: Thu, 19 Nov 2026 23:48:41 +1100 Subject: [PATCH 2/2] Scope the generated route parser warning to the route definition --- crates/openmacro-app/src/main.rs | 20 +++----------------- crates/openmacro-app/src/routes.rs | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 crates/openmacro-app/src/routes.rs diff --git a/crates/openmacro-app/src/main.rs b/crates/openmacro-app/src/main.rs index 63caeb4..64893f3 100644 --- a/crates/openmacro-app/src/main.rs +++ b/crates/openmacro-app/src/main.rs @@ -15,34 +15,20 @@ mod health; mod keypad; mod persist; mod prefs; +mod routes; mod seed; mod state; mod updater; use dioxus::prelude::*; -use components::{Dashboard, FoodLog, Insight, More, Plan, Shell, check_for_update}; +use components::check_for_update; +pub use routes::Route; use state::{AppState, today}; const MAIN_CSS: Asset = asset!("/assets/main.css"); const ICON: Asset = asset!("/assets/icon-192.png"); -#[derive(Debug, Clone, Routable, PartialEq)] -#[rustfmt::skip] -pub enum Route { - #[layout(Shell)] - #[route("/")] - Dashboard {}, - #[route("/log")] - FoodLog {}, - #[route("/plan")] - Plan {}, - #[route("/more")] - More {}, - #[route("/insight/:metric")] - Insight { metric: String }, -} - fn main() { dioxus::launch(App); } diff --git a/crates/openmacro-app/src/routes.rs b/crates/openmacro-app/src/routes.rs new file mode 100644 index 0000000..d80ff4c --- /dev/null +++ b/crates/openmacro-app/src/routes.rs @@ -0,0 +1,22 @@ +// Routable generates an unreachable error branch when parsing a String route segment. +#![allow(unreachable_code)] + +use dioxus::prelude::*; + +use crate::components::{Dashboard, FoodLog, Insight, More, Plan, Shell}; + +#[derive(Debug, Clone, Routable, PartialEq)] +#[rustfmt::skip] +pub enum Route { + #[layout(Shell)] + #[route("/")] + Dashboard {}, + #[route("/log")] + FoodLog {}, + #[route("/plan")] + Plan {}, + #[route("/more")] + More {}, + #[route("/insight/:metric")] + Insight { metric: String }, +}