mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-22 19:40:14 -04:00
Save the full state each time
This commit is contained in:
parent
db470ddc36
commit
5480074d3a
@ -327,6 +327,19 @@ impl HttpStore {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn save_state(&self, state: std::rc::Rc<app_state::State>) -> Result<(), Error> {
|
||||
let mut plan = Vec::new();
|
||||
for (key, count) in state.recipe_counts.get_untracked().iter() {
|
||||
plan.push((key.clone(), *count.get_untracked() as i32));
|
||||
}
|
||||
self.save_plan(plan).await?;
|
||||
self.save_inventory_data(
|
||||
state.filtered_ingredients.get_untracked().as_ref().clone(),
|
||||
state.get_current_modified_amts(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn save_plan(&self, plan: Vec<(String, i32)>) -> Result<(), Error> {
|
||||
let mut path = self.root.clone();
|
||||
path.push_str("/plan");
|
||||
|
@ -18,6 +18,7 @@ use tracing::{debug, instrument, warn};
|
||||
|
||||
use recipes::{Ingredient, IngredientAccumulator, IngredientKey, Recipe};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct State {
|
||||
pub recipe_counts: RcSignal<BTreeMap<String, RcSignal<usize>>>,
|
||||
pub extras: RcSignal<Vec<(usize, (RcSignal<String>, RcSignal<String>))>>,
|
||||
|
@ -56,12 +56,8 @@ pub fn RecipePlan<G: Html>(cx: Scope) -> View<G> {
|
||||
let store = HttpStore::get_from_context(cx);
|
||||
let state = app_state::State::get_from_context(cx);
|
||||
spawn_local_scoped(cx, {
|
||||
let mut plan = Vec::new();
|
||||
for (key, count) in state.recipe_counts.get_untracked().iter() {
|
||||
plan.push((key.clone(), *count.get_untracked() as i32));
|
||||
}
|
||||
async move {
|
||||
store.save_plan(plan).await.expect("Failed to save plan");
|
||||
store.save_state(state).await.expect("Failed to save plan");
|
||||
}
|
||||
})
|
||||
});
|
||||
|
@ -191,16 +191,10 @@ pub fn ShoppingList<G: Html>(cx: Scope) -> View<G> {
|
||||
spawn_local_scoped(cx, {
|
||||
let state = crate::app_state::State::get_from_context(cx);
|
||||
let store = crate::api::HttpStore::get_from_context(cx);
|
||||
let filtered_ingredients = state.filtered_ingredients.get_untracked().as_ref().clone();
|
||||
let modified_amts = state.get_current_modified_amts();
|
||||
async move {
|
||||
debug!(
|
||||
?filtered_ingredients,
|
||||
?modified_amts,
|
||||
"Attempting save for inventory"
|
||||
);
|
||||
debug!(?state, "Attempting save for inventory");
|
||||
store
|
||||
.save_inventory_data(filtered_ingredients, modified_amts)
|
||||
.save_state(state)
|
||||
.await
|
||||
.expect("Unable to save inventory data");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user