API naming consistency save_ -> store_

This commit is contained in:
Jeremy Wall 2023-01-05 13:06:19 -05:00
parent 30293878fc
commit 96b03cb14a
3 changed files with 15 additions and 15 deletions

View File

@ -244,7 +244,7 @@ impl LocalStore {
} }
/// Save working plan to local storage. /// Save working plan to local storage.
pub fn save_plan(&self, plan: &Vec<(String, i32)>) { pub fn store_plan(&self, plan: &Vec<(String, i32)>) {
self.store self.store
.set("plan", &to_string(&plan).expect("Failed to serialize plan")) .set("plan", &to_string(&plan).expect("Failed to serialize plan"))
.expect("Failed to store plan'"); .expect("Failed to store plan'");
@ -483,7 +483,7 @@ impl HttpStore {
} }
#[instrument(skip(recipes), fields(count=recipes.len()))] #[instrument(skip(recipes), fields(count=recipes.len()))]
pub async fn save_recipes(&self, recipes: Vec<RecipeEntry>) -> Result<(), Error> { pub async fn store_recipes(&self, recipes: Vec<RecipeEntry>) -> Result<(), Error> {
let mut path = self.v2_path(); let mut path = self.v2_path();
path.push_str("/recipes"); path.push_str("/recipes");
for r in recipes.iter() { for r in recipes.iter() {
@ -506,7 +506,7 @@ impl HttpStore {
} }
#[instrument(skip(categories))] #[instrument(skip(categories))]
pub async fn save_categories(&self, categories: String) -> Result<(), Error> { pub async fn store_categories(&self, categories: String) -> Result<(), Error> {
let mut path = self.v2_path(); let mut path = self.v2_path();
path.push_str("/categories"); path.push_str("/categories");
let resp = reqwasm::http::Request::post(&path) let resp = reqwasm::http::Request::post(&path)
@ -523,15 +523,15 @@ impl HttpStore {
} }
#[instrument(skip_all)] #[instrument(skip_all)]
pub async fn save_app_state(&self, state: AppState) -> Result<(), Error> { pub async fn store_app_state(&self, state: AppState) -> Result<(), Error> {
let mut plan = Vec::new(); let mut plan = Vec::new();
for (key, count) in state.recipe_counts.iter() { for (key, count) in state.recipe_counts.iter() {
plan.push((key.clone(), *count as i32)); plan.push((key.clone(), *count as i32));
} }
debug!("Saving plan data"); debug!("Saving plan data");
self.save_plan(plan).await?; self.store_plan(plan).await?;
debug!("Saving inventory data"); debug!("Saving inventory data");
self.save_inventory_data( self.store_inventory_data(
state.filtered_ingredients, state.filtered_ingredients,
state.modified_amts, state.modified_amts,
state state
@ -543,7 +543,7 @@ impl HttpStore {
.await .await
} }
pub async fn save_plan(&self, plan: Vec<(String, i32)>) -> Result<(), Error> { pub async fn store_plan(&self, plan: Vec<(String, i32)>) -> Result<(), Error> {
let mut path = self.v2_path(); let mut path = self.v2_path();
path.push_str("/plan"); path.push_str("/plan");
let resp = reqwasm::http::Request::post(&path) let resp = reqwasm::http::Request::post(&path)
@ -616,7 +616,7 @@ impl HttpStore {
} }
#[instrument] #[instrument]
pub async fn save_inventory_data( pub async fn store_inventory_data(
&self, &self,
filtered_ingredients: BTreeSet<IngredientKey>, filtered_ingredients: BTreeSet<IngredientKey>,
modified_amts: BTreeMap<IngredientKey, String>, modified_amts: BTreeMap<IngredientKey, String>,

View File

@ -184,7 +184,7 @@ impl StateMachine {
.iter() .iter()
.map(|(k, v)| (k.clone(), *v as i32)) .map(|(k, v)| (k.clone(), *v as i32))
.collect::<Vec<(String, i32)>>(); .collect::<Vec<(String, i32)>>();
local_store.save_plan(&plan); local_store.store_plan(&plan);
info!("Checking for user account data"); info!("Checking for user account data");
if let Some(user_data) = store.fetch_user_data().await { if let Some(user_data) = store.fetch_user_data().await {
debug!("Successfully got account data from server"); debug!("Successfully got account data from server");
@ -244,7 +244,7 @@ impl MessageMapper<Message, AppState> for StateMachine {
} }
let plan: Vec<(String, i32)> = let plan: Vec<(String, i32)> =
map.iter().map(|(s, i)| (s.clone(), *i as i32)).collect(); map.iter().map(|(s, i)| (s.clone(), *i as i32)).collect();
self.local_store.save_plan(&plan); self.local_store.store_plan(&plan);
original_copy.recipe_counts = map; original_copy.recipe_counts = map;
} }
Message::UpdateRecipeCount(id, count) => { Message::UpdateRecipeCount(id, count) => {
@ -254,7 +254,7 @@ impl MessageMapper<Message, AppState> for StateMachine {
.iter() .iter()
.map(|(s, i)| (s.clone(), *i as i32)) .map(|(s, i)| (s.clone(), *i as i32))
.collect(); .collect();
self.local_store.save_plan(&plan); self.local_store.store_plan(&plan);
} }
Message::AddExtra(amt, name) => { Message::AddExtra(amt, name) => {
original_copy.extras.push((amt, name)); original_copy.extras.push((amt, name));
@ -303,7 +303,7 @@ impl MessageMapper<Message, AppState> for StateMachine {
let store = self.store.clone(); let store = self.store.clone();
self.local_store.set_recipe_entry(&entry); self.local_store.set_recipe_entry(&entry);
spawn_local_scoped(cx, async move { spawn_local_scoped(cx, async move {
if let Err(e) = store.save_recipes(vec![entry]).await { if let Err(e) = store.store_recipes(vec![entry]).await {
error!(err=?e, "Unable to save Recipe"); error!(err=?e, "Unable to save Recipe");
} }
}); });
@ -313,7 +313,7 @@ impl MessageMapper<Message, AppState> for StateMachine {
self.local_store.set_categories(Some(&category_text)); self.local_store.set_categories(Some(&category_text));
let store = self.store.clone(); let store = self.store.clone();
spawn_local_scoped(cx, async move { spawn_local_scoped(cx, async move {
if let Err(e) = store.save_categories(category_text).await { if let Err(e) = store.store_categories(category_text).await {
error!(?e, "Failed to save categories"); error!(?e, "Failed to save categories");
} }
}); });
@ -352,7 +352,7 @@ impl MessageMapper<Message, AppState> for StateMachine {
let original_copy = original_copy.clone(); let original_copy = original_copy.clone();
let store = self.store.clone(); let store = self.store.clone();
spawn_local_scoped(cx, async move { spawn_local_scoped(cx, async move {
if let Err(e) = store.save_app_state(original_copy).await { if let Err(e) = store.store_app_state(original_copy).await {
error!(err=?e, "Error saving app state") error!(err=?e, "Error saving app state")
}; };
f.map(|f| f()); f.map(|f| f());

View File

@ -95,7 +95,7 @@ pub fn Editor<'ctx, G: Html>(cx: Scope<'ctx>, props: RecipeComponentProps<'ctx>)
async move { async move {
debug!("Attempting to save recipe"); debug!("Attempting to save recipe");
if let Err(e) = store if let Err(e) = store
.save_recipes(vec![RecipeEntry( .store_recipes(vec![RecipeEntry(
id.get_untracked().as_ref().clone(), id.get_untracked().as_ref().clone(),
text.get_untracked().as_ref().clone(), text.get_untracked().as_ref().clone(),
)]) )])