2022-02-02 16:29:27 -05:00
|
|
|
// Copyright 2022 Jeremy Wall
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
use crate::service::AppService;
|
|
|
|
|
|
|
|
use recipes;
|
|
|
|
use sycamore::{context::use_context, prelude::*};
|
|
|
|
|
|
|
|
#[component(Steps<G>)]
|
|
|
|
fn steps(steps: ReadSignal<Vec<recipes::Step>>) -> View<G> {
|
|
|
|
view! {
|
|
|
|
h2 { "Steps: " }
|
2022-02-02 16:57:24 -05:00
|
|
|
div(class="recipe_steps") {
|
2022-02-02 16:29:27 -05:00
|
|
|
Indexed(IndexedProps{
|
|
|
|
iterable: steps,
|
|
|
|
template: |step: recipes::Step| { view! {
|
2022-02-02 16:57:24 -05:00
|
|
|
div {
|
2022-02-12 15:31:35 -05:00
|
|
|
h3 { "Instructions" }
|
2022-02-02 16:29:27 -05:00
|
|
|
ul(class="ingredients") {
|
|
|
|
Indexed(IndexedProps{
|
|
|
|
iterable: Signal::new(step.ingredients).handle(),
|
|
|
|
template: |i| { view! {
|
|
|
|
li {
|
2022-02-14 15:54:26 -05:00
|
|
|
(i.amt) " " (i.name) " " (i.form.as_ref().map(|f| format!("({})", f)).unwrap_or(String::new()))
|
2022-02-02 16:29:27 -05:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
})
|
|
|
|
}
|
2022-02-12 15:31:35 -05:00
|
|
|
div(class="instructions") {
|
|
|
|
(step.instructions)
|
|
|
|
}
|
2022-02-02 16:29:27 -05:00
|
|
|
}}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[component(Recipe<G>)]
|
|
|
|
pub fn recipe(idx: ReadSignal<usize>) -> View<G> {
|
|
|
|
let app_service = use_context::<AppService>();
|
2022-07-21 16:33:55 -04:00
|
|
|
let view = Signal::new(View::empty());
|
|
|
|
create_effect(cloned!((app_service, view) => move || {
|
|
|
|
if let Some((_, recipe)) = app_service.get_recipes().get().get(*idx.get()) {
|
|
|
|
let recipe = recipe.clone();
|
|
|
|
let title = create_memo(cloned!((recipe) => move || recipe.get().title.clone()));
|
|
|
|
let desc = create_memo(
|
|
|
|
cloned!((recipe) => move || recipe.clone().get().desc.clone().unwrap_or_else(|| String::new())),
|
|
|
|
);
|
|
|
|
let steps = create_memo(cloned!((recipe) => move || recipe.get().steps.clone()));
|
|
|
|
view.set(view! {
|
|
|
|
div(class="recipe") {
|
|
|
|
h1(class="recipe_title") { (title.get()) }
|
|
|
|
div(class="recipe_description") {
|
|
|
|
(desc.get())
|
|
|
|
}
|
|
|
|
Steps(steps)
|
|
|
|
}
|
|
|
|
});
|
2022-02-02 16:29:27 -05:00
|
|
|
}
|
2022-07-21 16:33:55 -04:00
|
|
|
}));
|
|
|
|
view! {
|
|
|
|
(view.get().as_ref())
|
2022-02-02 16:29:27 -05:00
|
|
|
}
|
|
|
|
}
|