From 1b04c0adce23df21e9e06b8b274a4074ad9b3066 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] Let people choose their default food entry tab --- crates/openmacro-app/src/components/logger.rs | 32 ++++------ crates/openmacro-app/src/components/more.rs | 16 ++++- crates/openmacro-app/src/prefs.rs | 61 +++++++++++++++++++ 3 files changed, 87 insertions(+), 22 deletions(-) diff --git a/crates/openmacro-app/src/components/logger.rs b/crates/openmacro-app/src/components/logger.rs index b558048..5a31c82 100644 --- a/crates/openmacro-app/src/components/logger.rs +++ b/crates/openmacro-app/src/components/logger.rs @@ -13,18 +13,9 @@ use crate::back::use_back_handler; use crate::food_search::{self, Database, FoundFood}; use crate::foods::plate_item; use crate::keypad::{self, Key}; -use crate::prefs; +use crate::prefs::{self, FoodEntryTab as Tab}; use crate::state::{AppState, CoachSnapshot, LogEntry, PlateItem, day_totals}; -#[derive(Debug, Clone, Copy, PartialEq)] -enum Tab { - Search, - Scan, - Ai, - QuickAdd, - Library, -} - #[component] pub fn Logger() -> Element { let mut state = use_context::(); @@ -43,7 +34,13 @@ pub fn Logger() -> Element { let foods_db = use_context::>>(); // A food being copied into a new custom food. let mut copying_food = use_signal(|| None::); - let mut tab = use_signal(|| Tab::Search); + let mut tab = use_signal(|| { + if state.recipe_edit.peek().is_some() { + Tab::Search + } else { + prefs::PREFS.peek().default_food_tab + } + }); let mut detail = use_signal(|| None::); // Set when a scanned barcode isn't found, to prefill a new custom food. let mut new_barcode = use_signal(|| None::); @@ -152,22 +149,15 @@ pub fn Logger() -> Element { } if !saving_recipe() { nav { class: "sheet-tabs", - for (value , label) in [ - (Tab::Search, "Search"), - (Tab::Scan, "Scan"), - (Tab::Ai, "AI"), - (Tab::QuickAdd, "Quick Add"), - (Tab::Library, "Library"), - ] - { + for value in Tab::ALL { button { - key: "{label}", + key: "{value.label()}", class: if tab() == value && detail().is_none() { "active" }, onclick: move |_| { detail.set(None); tab.set(value); }, - "{label}" + "{value.label()}" } } } diff --git a/crates/openmacro-app/src/components/more.rs b/crates/openmacro-app/src/components/more.rs index 4329b0e..6708524 100644 --- a/crates/openmacro-app/src/components/more.rs +++ b/crates/openmacro-app/src/components/more.rs @@ -8,7 +8,7 @@ use super::health::HealthConnect; use super::hour_label; use crate::export; use crate::food_search::{self, Database, FoodRegion}; -use crate::prefs::{EnergyUnit, PREFS, Theme, WeightUnit}; +use crate::prefs::{EnergyUnit, FoodEntryTab, PREFS, Theme, WeightUnit}; use crate::state::{AppState, CoachSnapshot, Data, today}; #[component] @@ -419,6 +419,20 @@ fn DisplaySettings() -> Element { } } } + div { class: "choice", + span { class: "choice-label", "Default food entry tab" } + div { class: "segmented even", + for tab in FoodEntryTab::ALL { + button { + key: "{tab.label()}", + class: if prefs.default_food_tab == tab { "active" }, + aria_pressed: prefs.default_food_tab == tab, + onclick: move |_| PREFS.write().default_food_tab = tab, + "{tab.label()}" + } + } + } + } div { class: "field-grid", label { class: "field", span { "Food log starts at" } diff --git a/crates/openmacro-app/src/prefs.rs b/crates/openmacro-app/src/prefs.rs index 9d1a51e..4c5d1de 100644 --- a/crates/openmacro-app/src/prefs.rs +++ b/crates/openmacro-app/src/prefs.rs @@ -38,6 +38,40 @@ impl Theme { } } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +#[cfg_attr( + not(target_arch = "wasm32"), + derive(serde::Serialize, serde::Deserialize) +)] +pub enum FoodEntryTab { + #[default] + Search, + Scan, + Ai, + QuickAdd, + Library, +} + +impl FoodEntryTab { + pub const ALL: [Self; 5] = [ + Self::Search, + Self::Scan, + Self::Ai, + Self::QuickAdd, + Self::Library, + ]; + + pub fn label(self) -> &'static str { + match self { + Self::Search => "Search", + Self::Scan => "Scan", + Self::Ai => "AI", + Self::QuickAdd => "Quick Add", + Self::Library => "Library", + } + } +} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[cfg_attr( not(target_arch = "wasm32"), @@ -47,6 +81,7 @@ impl Theme { pub struct Prefs { pub theme: Theme, pub clock_24h: bool, + pub default_food_tab: FoodEntryTab, pub energy: EnergyUnit, pub weight: WeightUnit, /// The food log's first and last hours (earlier or later entries @@ -62,6 +97,7 @@ impl Default for Prefs { Self { theme: Theme::default(), clock_24h: false, + default_food_tab: FoodEntryTab::default(), energy: EnergyUnit::default(), weight: WeightUnit::default(), log_first_hour: 6, @@ -166,3 +202,28 @@ pub fn apply_theme(theme: Theme) { theme.code() )); } + +#[cfg(all(test, not(target_arch = "wasm32")))] +mod tests { + use super::*; + + #[test] + fn older_preferences_keep_their_settings_and_open_search() { + let prefs: Prefs = serde_json::from_str(r#"{"theme":"Light","clock_24h":true}"#).unwrap(); + assert_eq!(prefs.theme, Theme::Light); + assert!(prefs.clock_24h); + assert_eq!(prefs.default_food_tab, FoodEntryTab::Search); + } + + #[test] + fn every_food_tab_can_be_saved_and_restored() { + for tab in FoodEntryTab::ALL { + let prefs = Prefs { + default_food_tab: tab, + ..Prefs::default() + }; + let saved = serde_json::to_string(&prefs).unwrap(); + assert_eq!(serde_json::from_str::(&saved).unwrap(), prefs); + } + } +} From 1f9f55cc05f921a8d41d84959df95250adca921b 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 }, +}