mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-21 19:29:49 -04:00
Display current plan date at the top
This commit is contained in:
parent
a320351041
commit
0ba5f18b22
@ -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<G> {
|
||||
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) }
|
||||
}
|
||||
}
|
||||
|
@ -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<G> {
|
||||
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) }
|
||||
}
|
||||
}
|
||||
|
@ -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<String>,
|
||||
pub plan_date: &'ctx ReadSignal<Option<NaiveDate>>,
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn PlanningPage<'a, G: Html>(cx: Scope<'a>, state: PageState<'a, G>) -> View<G> {
|
||||
let PageState { children, selected } = state;
|
||||
pub fn PlanningPage<'ctx, G: Html>(cx: Scope<'ctx>, state: PageState<'ctx, G>) -> View<G> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,13 @@ use sycamore::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub fn PlanPage<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View<G> {
|
||||
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) }
|
||||
}
|
||||
}
|
||||
|
@ -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 |_| {
|
||||
|
Loading…
x
Reference in New Issue
Block a user