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)
|
Ltr(self.get_ml() / LTR)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn normalize(self) -> Self {
|
pub fn normalize(&self) -> Self {
|
||||||
let ml = self.get_ml();
|
let ml = self.get_ml();
|
||||||
if (ml / GAL) >= ONE {
|
if (ml / GAL) >= ONE {
|
||||||
return self.into_gal();
|
return self.clone().into_gal();
|
||||||
}
|
}
|
||||||
if (ml / LTR) >= ONE {
|
if (ml / LTR) >= ONE {
|
||||||
return self.into_ltr();
|
return self.clone().into_ltr();
|
||||||
}
|
}
|
||||||
if (ml / QRT) >= ONE {
|
if (ml / QRT) >= ONE {
|
||||||
return self.into_qrt();
|
return self.clone().into_qrt();
|
||||||
}
|
}
|
||||||
if (ml / PINT) >= ONE {
|
if (ml / PINT) >= ONE {
|
||||||
return self.into_pint();
|
return self.clone().into_pint();
|
||||||
}
|
}
|
||||||
if (ml / CUP) >= ONE {
|
if (ml / CUP) >= ONE {
|
||||||
return self.into_cup();
|
return self.clone().into_cup();
|
||||||
}
|
}
|
||||||
if (ml / FLOZ) >= ONE {
|
if (ml / FLOZ) >= ONE {
|
||||||
return self.into_floz();
|
return self.clone().into_floz();
|
||||||
}
|
}
|
||||||
if (ml / TBSP) >= ONE {
|
if (ml / TBSP) >= ONE {
|
||||||
return self.into_tbsp();
|
return self.clone().into_tbsp();
|
||||||
}
|
}
|
||||||
if (ml / TSP) >= ONE {
|
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)
|
Self::Oz(self.get_grams() / OZ)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn normalize(self) -> Self {
|
pub fn normalize(&self) -> Self {
|
||||||
let grams = self.get_grams();
|
let grams = self.get_grams();
|
||||||
if (grams / KG) >= ONE {
|
if (grams / KG) >= ONE {
|
||||||
return self.into_kilo();
|
return self.clone().into_kilo();
|
||||||
}
|
}
|
||||||
if (grams / LB) >= ONE {
|
if (grams / LB) >= ONE {
|
||||||
return self.into_pound();
|
return self.clone().into_pound();
|
||||||
}
|
}
|
||||||
if (grams / OZ) >= ONE {
|
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(),
|
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 {
|
impl Display for Measure {
|
||||||
|
@ -23,8 +23,8 @@ struct RecipeCheckBoxProps {
|
|||||||
title: String,
|
title: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[component(RecipeCheckBox<G>)]
|
#[component(RecipeSelection<G>)]
|
||||||
fn recipe_check_box(props: RecipeCheckBoxProps) -> View<G> {
|
fn recipe_selection(props: RecipeCheckBoxProps) -> View<G> {
|
||||||
let app_service = use_context::<AppService>();
|
let app_service = use_context::<AppService>();
|
||||||
// This is total hack but it works around the borrow issues with
|
// This is total hack but it works around the borrow issues with
|
||||||
// the `view!` macro.
|
// the `view!` macro.
|
||||||
@ -33,7 +33,7 @@ fn recipe_check_box(props: RecipeCheckBoxProps) -> View<G> {
|
|||||||
let id_cloned_2 = id_as_str.clone();
|
let id_cloned_2 = id_as_str.clone();
|
||||||
let count = Signal::new(format!("{}", app_service.get_recipe_count_by_index(i)));
|
let count = Signal::new(format!("{}", app_service.get_recipe_count_by_index(i)));
|
||||||
view! {
|
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();
|
let mut app_service = app_service.clone();
|
||||||
console_log!("setting recipe id: {} to count: {}", i, *count.get());
|
console_log!("setting recipe id: {} to count: {}", i, *count.get());
|
||||||
app_service.set_recipe_count_by_index(i, count.get().parse().unwrap());
|
app_service.set_recipe_count_by_index(i, count.get().parse().unwrap());
|
||||||
@ -54,7 +54,7 @@ pub fn recipe_selector() -> View<G> {
|
|||||||
iterable: titles,
|
iterable: titles,
|
||||||
template: |(i, title)| {
|
template: |(i, title)| {
|
||||||
view! {
|
view! {
|
||||||
RecipeCheckBox(RecipeCheckBoxProps{i: i, title: title})
|
RecipeSelection(RecipeCheckBoxProps{i: i, title: title})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
key: |(i, title)| (*i, title.clone()),
|
key: |(i, title)| (*i, title.clone()),
|
||||||
@ -74,6 +74,7 @@ fn shopping_list() -> View<G> {
|
|||||||
.collect::<Vec<(IngredientKey, Ingredient)>>()
|
.collect::<Vec<(IngredientKey, Ingredient)>>()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO(jwall): Sort by categories and names.
|
||||||
view! {
|
view! {
|
||||||
table(class="shopping_list") {
|
table(class="shopping_list") {
|
||||||
tr {
|
tr {
|
||||||
@ -83,9 +84,10 @@ fn shopping_list() -> View<G> {
|
|||||||
Indexed(IndexedProps{
|
Indexed(IndexedProps{
|
||||||
iterable: ingredients,
|
iterable: ingredients,
|
||||||
template: |(_k, i)| {
|
template: |(_k, i)| {
|
||||||
|
let amt = Signal::new(format!("{}", i.amt.normalize()));
|
||||||
view! {
|
view! {
|
||||||
tr {
|
tr {
|
||||||
td { (i.amt) }
|
td { input(bind:value=amt.clone(), type="text") }
|
||||||
td { (i.name) }
|
td { (i.name) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ impl AppService {
|
|||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
console_error!("Error parsing recipe {}", e);
|
console_error!("Error parsing recipe {}", e);
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
console_debug!("We parsed a recipe {}", recipe.title);
|
console_debug!("We parsed a recipe {}", recipe.title);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user