mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-22 19:40:14 -04:00
Cleanup more unused after refactors
This commit is contained in:
parent
fdaf5ad70d
commit
0b7ff32d42
@ -53,7 +53,7 @@ impl AppState {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Message {
|
pub enum Message {
|
||||||
InitRecipeCounts(BTreeMap<String, usize>),
|
ResetRecipeCounts,
|
||||||
UpdateRecipeCount(String, usize),
|
UpdateRecipeCount(String, usize),
|
||||||
InitExtras(BTreeSet<(String, String)>),
|
InitExtras(BTreeSet<(String, String)>),
|
||||||
AddExtra(String, String),
|
AddExtra(String, String),
|
||||||
@ -64,6 +64,7 @@ pub enum Message {
|
|||||||
RemoveRecipe(String),
|
RemoveRecipe(String),
|
||||||
SetStaples(Option<Recipe>),
|
SetStaples(Option<Recipe>),
|
||||||
SetCategoryMap(String),
|
SetCategoryMap(String),
|
||||||
|
ResetInventory,
|
||||||
UpdateCategories,
|
UpdateCategories,
|
||||||
InitFilteredIngredient(BTreeSet<IngredientKey>),
|
InitFilteredIngredient(BTreeSet<IngredientKey>),
|
||||||
AddFilteredIngredient(IngredientKey),
|
AddFilteredIngredient(IngredientKey),
|
||||||
@ -105,6 +106,7 @@ fn filter_recipes(
|
|||||||
None => Ok((None, None)),
|
None => Ok((None, None)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StateMachine {
|
impl StateMachine {
|
||||||
async fn load_state(store: HttpStore, original: &Signal<AppState>) {
|
async fn load_state(store: HttpStore, original: &Signal<AppState>) {
|
||||||
let mut state = original.get().as_ref().clone();
|
let mut state = original.get().as_ref().clone();
|
||||||
@ -184,7 +186,11 @@ impl MessageMapper<Message, AppState> for StateMachine {
|
|||||||
fn map<'ctx>(&self, cx: Scope<'ctx>, msg: Message, original: &'ctx Signal<AppState>) {
|
fn map<'ctx>(&self, cx: Scope<'ctx>, msg: Message, original: &'ctx Signal<AppState>) {
|
||||||
let mut original_copy = original.get().as_ref().clone();
|
let mut original_copy = original.get().as_ref().clone();
|
||||||
match msg {
|
match msg {
|
||||||
Message::InitRecipeCounts(map) => {
|
Message::ResetRecipeCounts => {
|
||||||
|
let mut map = BTreeMap::new();
|
||||||
|
for (id, _) in original_copy.recipes.iter() {
|
||||||
|
map.insert(id.clone(), 0);
|
||||||
|
}
|
||||||
original_copy.recipe_counts = map;
|
original_copy.recipe_counts = map;
|
||||||
}
|
}
|
||||||
Message::UpdateRecipeCount(id, count) => {
|
Message::UpdateRecipeCount(id, count) => {
|
||||||
@ -251,6 +257,11 @@ impl MessageMapper<Message, AppState> for StateMachine {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Message::ResetInventory => {
|
||||||
|
original_copy.filtered_ingredients = BTreeSet::new();
|
||||||
|
original_copy.modified_amts = BTreeMap::new();
|
||||||
|
original_copy.extras = BTreeSet::new();
|
||||||
|
}
|
||||||
Message::InitFilteredIngredient(set) => {
|
Message::InitFilteredIngredient(set) => {
|
||||||
original_copy.filtered_ingredients = set;
|
original_copy.filtered_ingredients = set;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ use recipes::Recipe;
|
|||||||
use sycamore::prelude::*;
|
use sycamore::prelude::*;
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
use crate::app_state;
|
|
||||||
use crate::app_state::{Message, StateHandler};
|
use crate::app_state::{Message, StateHandler};
|
||||||
use crate::components::recipe_selection::*;
|
use crate::components::recipe_selection::*;
|
||||||
|
|
||||||
@ -54,10 +53,10 @@ pub fn RecipePlan<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> Vie
|
|||||||
view ! {cx,
|
view ! {cx,
|
||||||
tr { Keyed(
|
tr { Keyed(
|
||||||
iterable=r,
|
iterable=r,
|
||||||
view=|cx, sig| {
|
view=move |cx, sig| {
|
||||||
let title = create_memo(cx, move || sig.get().1.title.clone());
|
let title = create_memo(cx, move || sig.get().1.title.clone());
|
||||||
view! {cx,
|
view! {cx,
|
||||||
td { RecipeSelection(i=sig.get().0.to_owned(), title=title) }
|
td { RecipeSelection(i=sig.get().0.to_owned(), title=title, sh=sh) }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
key=|sig| sig.get().0.to_owned(),
|
key=|sig| sig.get().0.to_owned(),
|
||||||
@ -72,8 +71,7 @@ pub fn RecipePlan<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> Vie
|
|||||||
refresh_click.set(toggle);
|
refresh_click.set(toggle);
|
||||||
})
|
})
|
||||||
input(type="button", value="Clear All", on:click=move |_| {
|
input(type="button", value="Clear All", on:click=move |_| {
|
||||||
let state = app_state::State::get_from_context(cx);
|
sh.dispatch(cx, Message::ResetRecipeCounts);
|
||||||
state.reset_recipe_counts();
|
|
||||||
})
|
})
|
||||||
input(type="button", value="Save Plan", on:click=move |_| {
|
input(type="button", value="Save Plan", on:click=move |_| {
|
||||||
// Poor man's click event signaling.
|
// Poor man's click event signaling.
|
||||||
|
@ -16,24 +16,29 @@ use std::rc::Rc;
|
|||||||
use sycamore::prelude::*;
|
use sycamore::prelude::*;
|
||||||
use tracing::{debug, instrument};
|
use tracing::{debug, instrument};
|
||||||
|
|
||||||
use crate::app_state;
|
use crate::app_state::{self, Message, StateHandler};
|
||||||
|
|
||||||
#[derive(Props)]
|
#[derive(Props)]
|
||||||
pub struct RecipeCheckBoxProps<'ctx> {
|
pub struct RecipeCheckBoxProps<'ctx> {
|
||||||
pub i: String,
|
pub i: String,
|
||||||
pub title: &'ctx ReadSignal<String>,
|
pub title: &'ctx ReadSignal<String>,
|
||||||
|
pub sh: StateHandler<'ctx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(props, cx), fields(
|
#[instrument(skip(props, cx), fields(
|
||||||
idx=%props.i,
|
id=%props.i,
|
||||||
title=%props.title.get()
|
title=%props.title.get()
|
||||||
))]
|
))]
|
||||||
#[component]
|
#[component]
|
||||||
pub fn RecipeSelection<G: Html>(cx: Scope, props: RecipeCheckBoxProps) -> View<G> {
|
pub fn RecipeSelection<'ctx, G: Html>(
|
||||||
|
cx: Scope<'ctx>,
|
||||||
|
props: RecipeCheckBoxProps<'ctx>,
|
||||||
|
) -> View<G> {
|
||||||
|
let RecipeCheckBoxProps { i, title, sh } = props;
|
||||||
let state = app_state::State::get_from_context(cx);
|
let state = app_state::State::get_from_context(cx);
|
||||||
// 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.
|
||||||
let id = Rc::new(props.i);
|
let id = Rc::new(i);
|
||||||
let count = create_signal(
|
let count = create_signal(
|
||||||
cx,
|
cx,
|
||||||
format!(
|
format!(
|
||||||
@ -52,7 +57,7 @@ pub fn RecipeSelection<G: Html>(cx: Scope, props: RecipeCheckBoxProps) -> View<G
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let title = props.title.get().clone();
|
let title = title.get().clone();
|
||||||
let for_id = id.clone();
|
let for_id = id.clone();
|
||||||
let href = format!("/ui/recipe/view/{}", id);
|
let href = format!("/ui/recipe/view/{}", id);
|
||||||
let name = format!("recipe_id:{}", id);
|
let name = format!("recipe_id:{}", id);
|
||||||
@ -60,9 +65,8 @@ pub fn RecipeSelection<G: Html>(cx: Scope, props: RecipeCheckBoxProps) -> View<G
|
|||||||
div() {
|
div() {
|
||||||
label(for=for_id) { a(href=href) { (*title) } }
|
label(for=for_id) { a(href=href) { (*title) } }
|
||||||
input(type="number", class="item-count-sel", min="0", bind:value=count, name=name, on:change=move |_| {
|
input(type="number", class="item-count-sel", min="0", bind:value=count, name=name, on:change=move |_| {
|
||||||
let state = app_state::State::get_from_context(cx);
|
|
||||||
debug!(idx=%id, count=%(*count.get()), "setting recipe count");
|
debug!(idx=%id, count=%(*count.get()), "setting recipe count");
|
||||||
state.set_recipe_count_by_index(id.as_ref(), count.get().parse().expect("recipe count isn't a valid usize number"));
|
sh.dispatch(cx, Message::UpdateRecipeCount(id.as_ref().clone(), count.get().parse().expect("Count is not a valid usize")));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,11 @@
|
|||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
use std::collections::{BTreeMap, BTreeSet};
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
use recipes::{IngredientAccumulator, IngredientKey};
|
use recipes::{IngredientAccumulator, IngredientKey};
|
||||||
use sycamore::prelude::*;
|
use sycamore::prelude::*;
|
||||||
use tracing::{debug, info, instrument};
|
use tracing::{info, instrument};
|
||||||
|
|
||||||
use crate::app_state::{Message, StateHandler};
|
use crate::app_state::{Message, StateHandler};
|
||||||
|
|
||||||
@ -191,72 +191,23 @@ fn make_shopping_table<'ctx, G: Html>(
|
|||||||
#[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> {
|
||||||
let filtered_keys = sh.get_selector(cx, |state| state.get().filtered_ingredients.clone());
|
|
||||||
let ingredients_map = create_rc_signal(BTreeMap::new());
|
|
||||||
let show_staples = create_signal(cx, true);
|
let show_staples = create_signal(cx, true);
|
||||||
let save_click = create_signal(cx, ());
|
let save_click = create_signal(cx, ());
|
||||||
create_effect(cx, {
|
|
||||||
let state = crate::app_state::State::get_from_context(cx);
|
|
||||||
let ingredients_map = ingredients_map.clone();
|
|
||||||
move || {
|
|
||||||
ingredients_map.set(state.get_shopping_list(*show_staples.get()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
debug!(ingredients_map=?ingredients_map.get_untracked());
|
|
||||||
let ingredients = create_memo(cx, {
|
|
||||||
let filtered_keys = filtered_keys.clone();
|
|
||||||
let ingredients_map = ingredients_map.clone();
|
|
||||||
move || {
|
|
||||||
let mut ingredients = Vec::new();
|
|
||||||
// This has the effect of sorting the ingredients by category
|
|
||||||
for (_, ingredients_list) in ingredients_map.get().iter() {
|
|
||||||
for (i, recipes) in ingredients_list.iter() {
|
|
||||||
if !filtered_keys.get().contains(&i.key()) {
|
|
||||||
ingredients.push((i.key(), (i.clone(), recipes.clone())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ingredients
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let table_view = create_signal(cx, View::empty());
|
|
||||||
create_effect(cx, {
|
|
||||||
let state = crate::app_state::State::get_from_context(cx);
|
|
||||||
move || {
|
|
||||||
if (ingredients.get().len() > 0) || (state.extras.get().len() > 0) {
|
|
||||||
table_view.set(make_shopping_table(cx, sh, show_staples));
|
|
||||||
} else {
|
|
||||||
table_view.set(View::empty());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
create_effect(cx, move || {
|
create_effect(cx, move || {
|
||||||
save_click.track();
|
save_click.track();
|
||||||
info!("Registering save request for inventory");
|
info!("Registering save request for inventory");
|
||||||
sh.dispatch(cx, Message::SaveState);
|
sh.dispatch(cx, Message::SaveState);
|
||||||
});
|
});
|
||||||
let state = crate::app_state::State::get_from_context(cx);
|
|
||||||
view! {cx,
|
view! {cx,
|
||||||
h1 { "Shopping List " }
|
h1 { "Shopping List " }
|
||||||
label(for="show_staples_cb") { "Show staples" }
|
label(for="show_staples_cb") { "Show staples" }
|
||||||
input(id="show_staples_cb", type="checkbox", bind:checked=show_staples)
|
input(id="show_staples_cb", type="checkbox", bind:checked=show_staples)
|
||||||
(table_view.get().as_ref().clone())
|
(make_shopping_table(cx, sh, show_staples))
|
||||||
input(type="button", value="Add Item", class="no-print", on:click=move |_| {
|
input(type="button", value="Add Item", class="no-print", on:click=move |_| {
|
||||||
let mut cloned_extras: Vec<(RcSignal<String>, RcSignal<String>)> = (*state.extras.get()).iter().map(|(_, tpl)| tpl.clone()).collect();
|
sh.dispatch(cx, Message::AddExtra(String::new(), String::new()));
|
||||||
cloned_extras.push((create_rc_signal("".to_owned()), create_rc_signal("".to_owned())));
|
|
||||||
state.extras.set(cloned_extras.drain(0..).enumerate().collect());
|
|
||||||
})
|
})
|
||||||
input(type="button", value="Reset", class="no-print", on:click={
|
input(type="button", value="Reset", class="no-print", on:click=move |_| {
|
||||||
//let state = crate::app_state::State::get_from_context(cx);
|
sh.dispatch(cx, Message::ResetInventory);
|
||||||
move |_| {
|
|
||||||
// FIXME(jwall): This should be an event.
|
|
||||||
// // TODO(jwall): We should actually pop up a modal here or use a different set of items.
|
|
||||||
// ingredients_map.set(state.get_shopping_list(*show_staples.get()));
|
|
||||||
// // clear the filter_signal
|
|
||||||
// filtered_keys.set(BTreeSet::new());
|
|
||||||
// state.modified_amts.set(BTreeMap::new());
|
|
||||||
// state.extras.set(Vec::new());
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
input(type="button", value="Save", class="no-print", on:click=|_| {
|
input(type="button", value="Save", class="no-print", on:click=|_| {
|
||||||
save_click.trigger_subscribers();
|
save_click.trigger_subscribers();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user