diff --git a/recipes/src/lib.rs b/recipes/src/lib.rs index 08615a3..71d654b 100644 --- a/recipes/src/lib.rs +++ b/recipes/src/lib.rs @@ -167,7 +167,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)] +#[derive(PartialEq, PartialOrd, Eq, Ord, Clone, Hash)] pub struct IngredientKey(String, Option, String); /// Ingredient in a recipe. The `name` and `form` fields with the measurement type diff --git a/web/src/components/shopping.rs b/web/src/components/shopping.rs index dfac909..c120cbb 100644 --- a/web/src/components/shopping.rs +++ b/web/src/components/shopping.rs @@ -14,7 +14,7 @@ use crate::components::Recipe; use crate::console_log; use crate::service::AppService; -use std::rc::Rc; +use std::{collections::HashSet, rc::Rc}; use recipes::{Ingredient, IngredientKey}; use sycamore::{context::use_context, prelude::*}; @@ -66,11 +66,14 @@ pub fn recipe_selector() -> View { #[component(ShoppingList)] fn shopping_list() -> View { let app_service = use_context::(); + let filtered_keys = Signal::new(HashSet::new()); + let filter_signal = filtered_keys.clone(); let ingredients = create_memo(move || { let ingredients = app_service.get_shopping_list(); ingredients .iter() .map(|(k, v)| (k.clone(), v.clone())) + .filter(|(k, _v)| !filter_signal.get().contains(k)) .collect::>() }); @@ -84,16 +87,19 @@ fn shopping_list() -> View { } Indexed(IndexedProps{ iterable: ingredients, - template: |(_k, i)| { + template: move |(k, i)| { let amt = Signal::new(format!("{}", i.amt.normalize())); let name = i.name; let form = i.form.map(|form| format!("({})", form)).unwrap_or_default(); + let filtered_keys = filtered_keys.clone(); view! { tr { - // TODO(jwall): What is the mechanism for deleting ingredients - // from the list? td { input(bind:value=amt.clone(), type="text") } - td { (name) " " (form) } + td {input(type="button", value="X", on:click=move |_| { + let mut keyset = (*filtered_keys.get()).clone(); + keyset.insert(k.clone()); + filtered_keys.set(keyset); + }) " " (name) " " (form) } } } },