mirror of
https://github.com/zaphar/kitchen.git
synced 2025-07-21 19:29:49 -04:00
Handle 0 count menu items properly
This commit is contained in:
parent
5296ed10c1
commit
b84b2722aa
@ -25,9 +25,7 @@ fn steps(steps: ReadSignal<Vec<recipes::Step>>) -> View<G> {
|
||||
iterable: steps,
|
||||
template: |step: recipes::Step| { view! {
|
||||
div {
|
||||
div(class="instructions") {
|
||||
(step.instructions)
|
||||
}
|
||||
h3 { "Instructions" }
|
||||
ul(class="ingredients") {
|
||||
Indexed(IndexedProps{
|
||||
iterable: Signal::new(step.ingredients).handle(),
|
||||
@ -38,6 +36,9 @@ fn steps(steps: ReadSignal<Vec<recipes::Step>>) -> View<G> {
|
||||
}}
|
||||
})
|
||||
}
|
||||
div(class="instructions") {
|
||||
(step.instructions)
|
||||
}
|
||||
}}
|
||||
}
|
||||
})
|
||||
|
@ -101,12 +101,13 @@ fn shopping_list() -> View<G> {
|
||||
#[component(RecipeList<G>)]
|
||||
fn recipe_list() -> View<G> {
|
||||
let app_service = use_context::<AppService>();
|
||||
let menu_list = app_service.get_menu_list();
|
||||
let menu_list = create_memo(move || app_service.get_menu_list());
|
||||
view! {
|
||||
h1 { "Recipe List" }
|
||||
Indexed(IndexedProps{
|
||||
iterable: menu_list,
|
||||
template: |(idx, _count)| {
|
||||
console_log!("Rendering recipe index: {}", idx);
|
||||
let idx = Signal::new(idx);
|
||||
view ! {
|
||||
Recipe(idx.handle())
|
||||
|
@ -93,15 +93,14 @@ impl AppService {
|
||||
self.recipes.clone()
|
||||
}
|
||||
|
||||
pub fn get_menu_list(&self) -> ReadSignal<Vec<(usize, usize)>> {
|
||||
let menu_list = self.menu_list.clone();
|
||||
create_memo(move || {
|
||||
menu_list
|
||||
.get()
|
||||
.iter()
|
||||
.map(|(idx, count)| (*idx, *count))
|
||||
.collect::<Vec<(usize, usize)>>()
|
||||
})
|
||||
pub fn get_menu_list(&self) -> Vec<(usize, usize)> {
|
||||
self.menu_list
|
||||
.get()
|
||||
.iter()
|
||||
// We exclude recipes in the menu_list with count 0
|
||||
.filter(|&(_, count)| *count != 0)
|
||||
.map(|(idx, count)| (*idx, *count))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn set_recipes(&mut self, mut recipes: Vec<(usize, Recipe)>) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user