diff --git a/web/src/pages/planning/cook.rs b/web/src/pages/planning/cook.rs index 2ae3cf9..e213f5b 100644 --- a/web/src/pages/planning/cook.rs +++ b/web/src/pages/planning/cook.rs @@ -18,9 +18,13 @@ use crate::{app_state::StateHandler, components::recipe_list::*}; #[component] pub fn CookPage<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View { + let current_plan = sh.get_selector(cx, |state| { + state.get().selected_plan_date + }); view! {cx, PlanningPage( selected=Some("Cook".to_owned()), + plan_date = current_plan, ) { RecipeList(sh) } } } diff --git a/web/src/pages/planning/inventory.rs b/web/src/pages/planning/inventory.rs index 39a84ea..67bb43e 100644 --- a/web/src/pages/planning/inventory.rs +++ b/web/src/pages/planning/inventory.rs @@ -18,9 +18,13 @@ use crate::{app_state::StateHandler, components::shopping_list::*}; #[component] pub fn InventoryPage<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View { + let current_plan = sh.get_selector(cx, |state| { + state.get().selected_plan_date + }); view! {cx, PlanningPage( selected=Some("Inventory".to_owned()), + plan_date = current_plan, ) { ShoppingList(sh) } } } diff --git a/web/src/pages/planning/mod.rs b/web/src/pages/planning/mod.rs index 940e35b..27fe3a1 100644 --- a/web/src/pages/planning/mod.rs +++ b/web/src/pages/planning/mod.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. use crate::components::tabs::*; +use chrono::NaiveDate; use sycamore::prelude::*; pub mod cook; @@ -25,14 +26,19 @@ pub use plan::*; pub use select::*; #[derive(Props)] -pub struct PageState<'a, G: Html> { - pub children: Children<'a, G>, +pub struct PageState<'ctx, G: Html> { + pub children: Children<'ctx, G>, pub selected: Option, + pub plan_date: &'ctx ReadSignal>, } #[component] -pub fn PlanningPage<'a, G: Html>(cx: Scope<'a>, state: PageState<'a, G>) -> View { - let PageState { children, selected } = state; +pub fn PlanningPage<'ctx, G: Html>(cx: Scope<'ctx>, state: PageState<'ctx, G>) -> View { + let PageState { + children, + selected, + plan_date, + } = state; let children = children.call(cx); let planning_tabs: Vec<(String, &'static str)> = vec![ ("/ui/planning/select".to_owned(), "Select"), @@ -45,6 +51,10 @@ pub fn PlanningPage<'a, G: Html>(cx: Scope<'a>, state: PageState<'a, G>) -> View TabbedView( selected=selected, tablist=planning_tabs, - ) { (children) } + ) { div { + "Plan Date: " (plan_date.get().map_or(String::from("Unknown"), |d| format!("{}", d))) + } + (children) + } } } diff --git a/web/src/pages/planning/plan.rs b/web/src/pages/planning/plan.rs index f3f4975..a8e3bba 100644 --- a/web/src/pages/planning/plan.rs +++ b/web/src/pages/planning/plan.rs @@ -18,9 +18,13 @@ use sycamore::prelude::*; #[component] pub fn PlanPage<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View { + let current_plan = sh.get_selector(cx, |state| { + state.get().selected_plan_date + }); view! {cx, PlanningPage( selected=Some("Plan".to_owned()), + plan_date = current_plan, ) { RecipePlan(sh) } } } diff --git a/web/src/pages/planning/select.rs b/web/src/pages/planning/select.rs index f037003..2057926 100644 --- a/web/src/pages/planning/select.rs +++ b/web/src/pages/planning/select.rs @@ -32,9 +32,13 @@ pub fn SelectPage<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> Vie plans.sort_unstable_by(|d1, d2| d2.cmp(d1)); plans }); + let current_plan = sh.get_selector(cx, |state| { + state.get().selected_plan_date + }); view! {cx, PlanningPage( selected=Some("Select".to_owned()), + plan_date = current_plan.clone(), ) { PlanList(sh=sh, list=plan_dates) button(on:click=move |_| {