diff --git a/web/src/api.rs b/web/src/api.rs index cd5d93f..640a4b1 100644 --- a/web/src/api.rs +++ b/web/src/api.rs @@ -372,7 +372,7 @@ impl HttpStore { } #[instrument] - pub async fn get_user_data(&self) -> Option { + pub async fn fetch_user_data(&self) -> Option { debug!("Retrieving User Account data"); let mut path = self.v2_path(); path.push_str("/account"); @@ -393,7 +393,7 @@ impl HttpStore { return None; } //#[instrument] - pub async fn get_categories(&self) -> Result, Error> { + pub async fn fetch_categories(&self) -> Result, Error> { let mut path = self.v2_path(); path.push_str("/categories"); let resp = match reqwasm::http::Request::get(&path).send().await { @@ -419,7 +419,7 @@ impl HttpStore { } #[instrument] - pub async fn get_recipes(&self) -> Result>, Error> { + pub async fn fetch_recipes(&self) -> Result>, Error> { let mut path = self.v2_path(); path.push_str("/recipes"); let resp = match reqwasm::http::Request::get(&path).send().await { @@ -445,7 +445,7 @@ impl HttpStore { } } - pub async fn get_recipe_text + std::fmt::Display>( + pub async fn fetch_recipe_text + std::fmt::Display>( &self, id: S, ) -> Result, Error> { @@ -559,7 +559,7 @@ impl HttpStore { } } - pub async fn get_plan(&self) -> Result>, Error> { + pub async fn fetch_plan(&self) -> Result>, Error> { let mut path = self.v2_path(); path.push_str("/plan"); let resp = reqwasm::http::Request::get(&path).send().await?; @@ -576,6 +576,7 @@ impl HttpStore { } } + pub async fn fetch_inventory_data( &self, ) -> Result< ( diff --git a/web/src/app_state.rs b/web/src/app_state.rs index 1fb6cf2..ecb784b 100644 --- a/web/src/app_state.rs +++ b/web/src/app_state.rs @@ -153,6 +153,7 @@ impl StateMachine { ) -> Result<(), crate::api::Error> { let mut state = original.get().as_ref().clone(); info!("Synchronizing Recipes"); + let recipe_entries = &store.fetch_recipes().await?; let (staples, recipes) = filter_recipes(&recipe_entries)?; if let Some(recipes) = recipes { state.staples = staples; @@ -162,6 +163,7 @@ impl StateMachine { local_store.set_all_recipes(recipe_entries); } + let plan = store.fetch_plan().await?; if let Some(plan) = plan { // set the counts. let mut plan_map = BTreeMap::new(); @@ -184,6 +186,7 @@ impl StateMachine { .collect::>(); local_store.save_plan(&plan); info!("Checking for user account data"); + if let Some(user_data) = store.fetch_user_data().await { debug!("Successfully got account data from server"); local_store.set_user_data(Some(&user_data)); state.auth = Some(user_data); @@ -193,6 +196,7 @@ impl StateMachine { state.auth = user_data; } info!("Synchronizing categories"); + match store.fetch_categories().await { Ok(Some(categories_content)) => { debug!(categories=?categories_content); local_store.set_categories(Some(&categories_content)); @@ -207,6 +211,7 @@ impl StateMachine { } } info!("Synchronizing inventory data"); + match store.fetch_inventory_data().await { Ok((filtered_ingredients, modified_amts, extra_items)) => { local_store.set_inventory_data(( &filtered_ingredients, diff --git a/web/src/components/add_recipe.rs b/web/src/components/add_recipe.rs index f740189..f007127 100644 --- a/web/src/components/add_recipe.rs +++ b/web/src/components/add_recipe.rs @@ -63,7 +63,7 @@ pub fn AddRecipe<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View async move { let entry = entry.get_untracked(); // TODO(jwall): Better error reporting here. - match store.get_recipe_text(entry.recipe_id()).await { + match store.fetch_recipe_text(entry.recipe_id()).await { Ok(Some(_)) => { // TODO(jwall): We should tell the user that this id already exists info!(recipe_id = entry.recipe_id(), "Recipe already exists"); diff --git a/web/src/components/categories.rs b/web/src/components/categories.rs index 3e4c527..b2345c9 100644 --- a/web/src/components/categories.rs +++ b/web/src/components/categories.rs @@ -51,7 +51,7 @@ pub fn Categories<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> Vie let store = crate::api::HttpStore::get_from_context(cx); async move { if let Some(js) = store - .get_categories() + .fetch_categories() .await .expect("Failed to get categories.") { diff --git a/web/src/components/recipe.rs b/web/src/components/recipe.rs index 0677ef0..c124c0b 100644 --- a/web/src/components/recipe.rs +++ b/web/src/components/recipe.rs @@ -54,7 +54,7 @@ pub fn Editor<'ctx, G: Html>(cx: Scope<'ctx>, props: RecipeComponentProps<'ctx>) let store = store.clone(); async move { let entry = store - .get_recipe_text(recipe_id.as_str()) + .fetch_recipe_text(recipe_id.as_str()) .await .expect("Failure getting recipe"); if let Some(entry) = entry {