Load plan_dates during the load state phase

This commit is contained in:
Jeremy Wall 2023-01-17 13:31:51 -05:00
parent be74b24f6b
commit 3f0836dad2

View File

@ -16,6 +16,7 @@ use std::{
fmt::Debug, fmt::Debug,
}; };
use chrono::NaiveDate;
use client_api::UserData; use client_api::UserData;
use recipes::{parse, Ingredient, IngredientKey, Recipe, RecipeEntry}; use recipes::{parse, Ingredient, IngredientKey, Recipe, RecipeEntry};
use sycamore::futures::spawn_local_scoped; use sycamore::futures::spawn_local_scoped;
@ -36,6 +37,7 @@ pub struct AppState {
pub filtered_ingredients: BTreeSet<IngredientKey>, pub filtered_ingredients: BTreeSet<IngredientKey>,
pub modified_amts: BTreeMap<IngredientKey, String>, pub modified_amts: BTreeMap<IngredientKey, String>,
pub auth: Option<UserData>, pub auth: Option<UserData>,
pub plan_dates: BTreeSet<NaiveDate>,
} }
impl AppState { impl AppState {
@ -49,6 +51,7 @@ impl AppState {
filtered_ingredients: BTreeSet::new(), filtered_ingredients: BTreeSet::new(),
modified_amts: BTreeMap::new(), modified_amts: BTreeMap::new(),
auth: None, auth: None,
plan_dates: BTreeSet::new(),
} }
} }
} }
@ -180,6 +183,12 @@ impl StateMachine {
local_store.set_all_recipes(recipe_entries); local_store.set_all_recipes(recipe_entries);
} }
info!("Fetching meal plan list");
let plan_dates = store.fetch_plan_dates().await?;
if let Some(mut plan_dates) = plan_dates {
debug!(?plan_dates, "meal plan list");
state.plan_dates = BTreeSet::from_iter(plan_dates.drain(0..));
}
info!("Synchronizing meal plan"); info!("Synchronizing meal plan");
let plan = store.fetch_plan().await?; let plan = store.fetch_plan().await?;
if let Some(plan) = plan { if let Some(plan) = plan {