mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-29 20:39:53 -04:00
Compare commits
No commits in common. "cc66c1f4f515dff52c91108501fce9a77fff8c7c" and "c77fa24515c5c98338026c88c5b6a54765ca31e4" have entirely different histories.
cc66c1f4f5
...
c77fa24515
@ -86,7 +86,6 @@ pub enum Message {
|
|||||||
UpdateCategory(String, String, Option<Box<dyn FnOnce()>>),
|
UpdateCategory(String, String, Option<Box<dyn FnOnce()>>),
|
||||||
ResetInventory,
|
ResetInventory,
|
||||||
AddFilteredIngredient(IngredientKey),
|
AddFilteredIngredient(IngredientKey),
|
||||||
RemoveFilteredIngredient(IngredientKey),
|
|
||||||
UpdateAmt(IngredientKey, String),
|
UpdateAmt(IngredientKey, String),
|
||||||
SetUserData(UserData),
|
SetUserData(UserData),
|
||||||
SaveState(Option<Box<dyn FnOnce()>>),
|
SaveState(Option<Box<dyn FnOnce()>>),
|
||||||
@ -125,9 +124,6 @@ impl Debug for Message {
|
|||||||
Self::AddFilteredIngredient(arg0) => {
|
Self::AddFilteredIngredient(arg0) => {
|
||||||
f.debug_tuple("AddFilteredIngredient").field(arg0).finish()
|
f.debug_tuple("AddFilteredIngredient").field(arg0).finish()
|
||||||
}
|
}
|
||||||
Self::RemoveFilteredIngredient(arg0) => {
|
|
||||||
f.debug_tuple("RemoveFilteredIngredient").field(arg0).finish()
|
|
||||||
}
|
|
||||||
Self::UpdateAmt(arg0, arg1) => {
|
Self::UpdateAmt(arg0, arg1) => {
|
||||||
f.debug_tuple("UpdateAmt").field(arg0).field(arg1).finish()
|
f.debug_tuple("UpdateAmt").field(arg0).field(arg1).finish()
|
||||||
}
|
}
|
||||||
@ -397,9 +393,6 @@ impl MessageMapper<Message, AppState> for StateMachine {
|
|||||||
Message::AddFilteredIngredient(key) => {
|
Message::AddFilteredIngredient(key) => {
|
||||||
original_copy.filtered_ingredients.insert(key);
|
original_copy.filtered_ingredients.insert(key);
|
||||||
}
|
}
|
||||||
Message::RemoveFilteredIngredient(key) => {
|
|
||||||
original_copy.filtered_ingredients.remove(&key);
|
|
||||||
}
|
|
||||||
Message::UpdateAmt(key, amt) => {
|
Message::UpdateAmt(key, amt) => {
|
||||||
original_copy.modified_amts.insert(key, amt);
|
original_copy.modified_amts.insert(key, amt);
|
||||||
}
|
}
|
||||||
|
@ -19,115 +19,6 @@ use tracing::{debug, info, instrument};
|
|||||||
|
|
||||||
use crate::app_state::{Message, StateHandler};
|
use crate::app_state::{Message, StateHandler};
|
||||||
|
|
||||||
#[instrument(skip_all)]
|
|
||||||
fn make_deleted_ingredients_rows<'ctx, G: Html>(
|
|
||||||
cx: Scope<'ctx>,
|
|
||||||
sh: StateHandler<'ctx>,
|
|
||||||
show_staples: &'ctx ReadSignal<bool>,
|
|
||||||
) -> View<G> {
|
|
||||||
debug!("Making ingredients rows");
|
|
||||||
let ingredients = sh.get_selector(cx, move |state| {
|
|
||||||
let state = state.get();
|
|
||||||
let category_map = &state.category_map;
|
|
||||||
debug!("building ingredient list from state");
|
|
||||||
let mut acc = IngredientAccumulator::new();
|
|
||||||
for (id, count) in state.recipe_counts.iter() {
|
|
||||||
for _ in 0..(*count) {
|
|
||||||
acc.accumulate_from(
|
|
||||||
state
|
|
||||||
.recipes
|
|
||||||
.get(id)
|
|
||||||
.expect(&format!("No such recipe id exists: {}", id)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if *show_staples.get() {
|
|
||||||
if let Some(staples) = &state.staples {
|
|
||||||
acc.accumulate_ingredients_for("Staples", staples.iter());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let mut ingredients = acc
|
|
||||||
.ingredients()
|
|
||||||
.into_iter()
|
|
||||||
// First we filter out any filtered ingredients
|
|
||||||
.filter(|(i, _)| state.filtered_ingredients.contains(i))
|
|
||||||
// Then we take into account our modified amts
|
|
||||||
.map(|(k, (i, rs))| {
|
|
||||||
let category = category_map
|
|
||||||
.get(&i.name)
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or_else(|| String::new());
|
|
||||||
if state.modified_amts.contains_key(&k) {
|
|
||||||
(
|
|
||||||
k.clone(),
|
|
||||||
(
|
|
||||||
i.name,
|
|
||||||
i.form,
|
|
||||||
category,
|
|
||||||
state.modified_amts.get(&k).unwrap().clone(),
|
|
||||||
rs,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
(
|
|
||||||
k.clone(),
|
|
||||||
(
|
|
||||||
i.name,
|
|
||||||
i.form,
|
|
||||||
category,
|
|
||||||
format!("{}", i.amt.normalize()),
|
|
||||||
rs,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<(
|
|
||||||
IngredientKey,
|
|
||||||
(String, Option<String>, String, String, BTreeSet<String>),
|
|
||||||
)>>();
|
|
||||||
ingredients.sort_by(|tpl1, tpl2| (&tpl1.1 .2, &tpl1.1 .0).cmp(&(&tpl2.1 .2, &tpl2.1 .0)));
|
|
||||||
ingredients
|
|
||||||
});
|
|
||||||
view!(
|
|
||||||
cx,
|
|
||||||
Indexed(
|
|
||||||
iterable = ingredients,
|
|
||||||
view = move |cx, (k, (name, form, category, amt, rs))| {
|
|
||||||
let category = if category == "" {
|
|
||||||
"other".to_owned()
|
|
||||||
} else {
|
|
||||||
category
|
|
||||||
};
|
|
||||||
let amt_signal = create_signal(cx, amt);
|
|
||||||
let k_clone = k.clone();
|
|
||||||
let form = form.map(|form| format!("({})", form)).unwrap_or_default();
|
|
||||||
let recipes = rs
|
|
||||||
.iter()
|
|
||||||
.fold(String::new(), |acc, s| format!("{}{},", acc, s))
|
|
||||||
.trim_end_matches(",")
|
|
||||||
.to_owned();
|
|
||||||
view! {cx,
|
|
||||||
tr {
|
|
||||||
td {
|
|
||||||
input(bind:value=amt_signal, class="width-5", type="text", on:change=move |_| {
|
|
||||||
sh.dispatch(cx, Message::UpdateAmt(k_clone.clone(), amt_signal.get_untracked().as_ref().clone()));
|
|
||||||
})
|
|
||||||
}
|
|
||||||
td {
|
|
||||||
input(type="button", class="fit-content no-print", value="Undo", on:click={
|
|
||||||
move |_| {
|
|
||||||
sh.dispatch(cx, Message::RemoveFilteredIngredient(k.clone()));
|
|
||||||
}})
|
|
||||||
}
|
|
||||||
td { (name) " " (form) "" br {} "" (category) "" }
|
|
||||||
td { (recipes) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[instrument(skip_all)]
|
#[instrument(skip_all)]
|
||||||
fn make_ingredients_rows<'ctx, G: Html>(
|
fn make_ingredients_rows<'ctx, G: Html>(
|
||||||
cx: Scope<'ctx>,
|
cx: Scope<'ctx>,
|
||||||
@ -300,27 +191,6 @@ fn make_shopping_table<'ctx, G: Html>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_deleted_items_table<'ctx, G: Html>(
|
|
||||||
cx: Scope<'ctx>,
|
|
||||||
sh: StateHandler<'ctx>,
|
|
||||||
show_staples: &'ctx ReadSignal<bool>,
|
|
||||||
) -> View<G> {
|
|
||||||
view! {cx,
|
|
||||||
h2 { "Deleted Items" }
|
|
||||||
table(class="pad-top shopping-list page-breaker container-fluid", role="grid") {
|
|
||||||
tr {
|
|
||||||
th { " Quantity " }
|
|
||||||
th { " Delete " }
|
|
||||||
th { " Ingredient " }
|
|
||||||
th { " Recipes " }
|
|
||||||
}
|
|
||||||
tbody {
|
|
||||||
(make_deleted_ingredients_rows(cx, sh, show_staples))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[instrument(skip_all)]
|
#[instrument(skip_all)]
|
||||||
#[component]
|
#[component]
|
||||||
pub fn ShoppingList<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View<G> {
|
pub fn ShoppingList<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View<G> {
|
||||||
@ -333,7 +203,6 @@ pub fn ShoppingList<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> V
|
|||||||
sh.dispatch(cx, Message::UpdateUseStaples(value));
|
sh.dispatch(cx, Message::UpdateUseStaples(value));
|
||||||
})
|
})
|
||||||
(make_shopping_table(cx, sh, show_staples))
|
(make_shopping_table(cx, sh, show_staples))
|
||||||
(make_deleted_items_table(cx, sh, show_staples))
|
|
||||||
button(class="no-print", on:click=move |_| {
|
button(class="no-print", on:click=move |_| {
|
||||||
info!("Registering add item request for inventory");
|
info!("Registering add item request for inventory");
|
||||||
sh.dispatch(cx, Message::AddExtra(String::new(), String::new()));
|
sh.dispatch(cx, Message::AddExtra(String::new(), String::new()));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user