Fixed bug in shopping list when missing categories

This commit is contained in:
Jeremy Wall 2022-05-06 21:24:00 -04:00
parent a0d8c07a4b
commit b9e5ebd705
2 changed files with 17 additions and 19 deletions

View File

@ -176,7 +176,7 @@ impl Step {
/// Unique identifier for an Ingredient. Ingredients are identified by name, form,
/// and measurement type. (Volume, Count, Weight)
#[derive(PartialEq, PartialOrd, Eq, Ord, Clone, Hash)]
#[derive(PartialEq, PartialOrd, Eq, Ord, Clone, Hash, Debug)]
pub struct IngredientKey(String, Option<String>, String);
/// Ingredient in a recipe. The `name` and `form` fields with the measurement type

View File

@ -25,17 +25,16 @@ use recipes::{parse, Ingredient, IngredientAccumulator, Recipe};
pub struct AppService {
recipes: Signal<Vec<(usize, Signal<Recipe>)>>,
staples: Signal<Option<Recipe>>,
category_map: Signal<Option<BTreeMap<String, String>>>,
category_map: Signal<BTreeMap<String, String>>,
menu_list: Signal<BTreeMap<usize, usize>>,
}
impl AppService {
pub fn new() -> Self {
let mut category_map = BTreeMap::new();
Self {
recipes: Signal::new(Vec::new()),
staples: Signal::new(None),
category_map: Signal::new(None),
category_map: Signal::new(BTreeMap::new()),
menu_list: Signal::new(BTreeMap::new()),
}
}
@ -193,9 +192,9 @@ impl AppService {
}
let mut ingredients = acc.ingredients();
let mut groups = BTreeMap::new();
self.category_map.get().as_ref().as_ref().map(|cm| {
let cat_map = self.category_map.get().clone();
for (_, (i, recipes)) in ingredients.iter_mut() {
let category = if let Some(cat) = cm.get(&i.name) {
let category = if let Some(cat) = cat_map.get(&i.name) {
cat.clone()
} else {
"other".to_owned()
@ -206,7 +205,6 @@ impl AppService {
.or_insert(vec![])
.push((i.clone(), recipes.clone()));
}
});
console_debug!("Category map {:?}", self.category_map);
// FIXM(jwall): Sort by categories and names.
groups
@ -246,6 +244,6 @@ impl AppService {
}
pub fn set_categories(&mut self, categories: BTreeMap<String, String>) {
self.category_map.set(Some(categories));
self.category_map.set(categories);
}
}