mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-22 19:40:14 -04:00
modifiable shopping list
This commit is contained in:
parent
42f6d3230a
commit
2282192678
@ -137,33 +137,33 @@ impl VolumeMeasure {
|
||||
Ltr(self.get_ml() / LTR)
|
||||
}
|
||||
|
||||
pub fn normalize(self) -> Self {
|
||||
pub fn normalize(&self) -> Self {
|
||||
let ml = self.get_ml();
|
||||
if (ml / GAL) >= ONE {
|
||||
return self.into_gal();
|
||||
return self.clone().into_gal();
|
||||
}
|
||||
if (ml / LTR) >= ONE {
|
||||
return self.into_ltr();
|
||||
return self.clone().into_ltr();
|
||||
}
|
||||
if (ml / QRT) >= ONE {
|
||||
return self.into_qrt();
|
||||
return self.clone().into_qrt();
|
||||
}
|
||||
if (ml / PINT) >= ONE {
|
||||
return self.into_pint();
|
||||
return self.clone().into_pint();
|
||||
}
|
||||
if (ml / CUP) >= ONE {
|
||||
return self.into_cup();
|
||||
return self.clone().into_cup();
|
||||
}
|
||||
if (ml / FLOZ) >= ONE {
|
||||
return self.into_floz();
|
||||
return self.clone().into_floz();
|
||||
}
|
||||
if (ml / TBSP) >= ONE {
|
||||
return self.into_tbsp();
|
||||
return self.clone().into_tbsp();
|
||||
}
|
||||
if (ml / TSP) >= ONE {
|
||||
return self.into_tsp();
|
||||
return self.clone().into_tsp();
|
||||
}
|
||||
return self.into_ml();
|
||||
return self.clone().into_ml();
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,18 +249,18 @@ impl WeightMeasure {
|
||||
Self::Oz(self.get_grams() / OZ)
|
||||
}
|
||||
|
||||
pub fn normalize(self) -> Self {
|
||||
pub fn normalize(&self) -> Self {
|
||||
let grams = self.get_grams();
|
||||
if (grams / KG) >= ONE {
|
||||
return self.into_kilo();
|
||||
return self.clone().into_kilo();
|
||||
}
|
||||
if (grams / LB) >= ONE {
|
||||
return self.into_pound();
|
||||
return self.clone().into_pound();
|
||||
}
|
||||
if (grams / OZ) >= ONE {
|
||||
return self.into_oz();
|
||||
return self.clone().into_oz();
|
||||
}
|
||||
return self.into_gram();
|
||||
return self.clone().into_gram();
|
||||
}
|
||||
}
|
||||
|
||||
@ -393,6 +393,14 @@ impl Measure {
|
||||
Weight(wm) => wm.plural(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn normalize(&self) -> Self {
|
||||
match self {
|
||||
Volume(vm) => Volume(vm.normalize()),
|
||||
Count(qty) => Count(qty.clone()),
|
||||
Weight(wm) => Weight(wm.normalize()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Measure {
|
||||
|
@ -23,8 +23,8 @@ struct RecipeCheckBoxProps {
|
||||
title: String,
|
||||
}
|
||||
|
||||
#[component(RecipeCheckBox<G>)]
|
||||
fn recipe_check_box(props: RecipeCheckBoxProps) -> View<G> {
|
||||
#[component(RecipeSelection<G>)]
|
||||
fn recipe_selection(props: RecipeCheckBoxProps) -> View<G> {
|
||||
let app_service = use_context::<AppService>();
|
||||
// This is total hack but it works around the borrow issues with
|
||||
// the `view!` macro.
|
||||
@ -33,7 +33,7 @@ fn recipe_check_box(props: RecipeCheckBoxProps) -> View<G> {
|
||||
let id_cloned_2 = id_as_str.clone();
|
||||
let count = Signal::new(format!("{}", app_service.get_recipe_count_by_index(i)));
|
||||
view! {
|
||||
input(type="number", min="0", bind:value=count.clone(), name="recipe_id", value=id_as_str.clone(), on:change=move |_| {
|
||||
input(type="number", min="0", bind:value=count.clone(), name=format!("recipe_id:{}", i), value=id_as_str.clone(), on:change=move |_| {
|
||||
let mut app_service = app_service.clone();
|
||||
console_log!("setting recipe id: {} to count: {}", i, *count.get());
|
||||
app_service.set_recipe_count_by_index(i, count.get().parse().unwrap());
|
||||
@ -54,7 +54,7 @@ pub fn recipe_selector() -> View<G> {
|
||||
iterable: titles,
|
||||
template: |(i, title)| {
|
||||
view! {
|
||||
RecipeCheckBox(RecipeCheckBoxProps{i: i, title: title})
|
||||
RecipeSelection(RecipeCheckBoxProps{i: i, title: title})
|
||||
}
|
||||
},
|
||||
key: |(i, title)| (*i, title.clone()),
|
||||
@ -74,6 +74,7 @@ fn shopping_list() -> View<G> {
|
||||
.collect::<Vec<(IngredientKey, Ingredient)>>()
|
||||
});
|
||||
|
||||
// TODO(jwall): Sort by categories and names.
|
||||
view! {
|
||||
table(class="shopping_list") {
|
||||
tr {
|
||||
@ -83,9 +84,10 @@ fn shopping_list() -> View<G> {
|
||||
Indexed(IndexedProps{
|
||||
iterable: ingredients,
|
||||
template: |(_k, i)| {
|
||||
let amt = Signal::new(format!("{}", i.amt.normalize()));
|
||||
view! {
|
||||
tr {
|
||||
td { (i.amt) }
|
||||
td { input(bind:value=amt.clone(), type="text") }
|
||||
td { (i.name) }
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ impl AppService {
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
console_error!("Error parsing recipe {}", e);
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
console_debug!("We parsed a recipe {}", recipe.title);
|
||||
|
Loading…
x
Reference in New Issue
Block a user