2022-03-15 18:01:25 -04: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 std::rc::Rc;
|
|
|
|
|
2022-08-12 21:41:19 -04:00
|
|
|
use sycamore::prelude::*;
|
2022-07-18 18:50:11 -04:00
|
|
|
use tracing::{debug, instrument};
|
|
|
|
|
2022-08-12 21:41:19 -04:00
|
|
|
use crate::service::get_appservice_from_context;
|
2022-03-15 18:01:25 -04:00
|
|
|
|
|
|
|
pub struct RecipeCheckBoxProps {
|
|
|
|
pub i: usize,
|
|
|
|
pub title: ReadSignal<String>,
|
|
|
|
}
|
|
|
|
|
2022-07-18 18:50:11 -04:00
|
|
|
#[instrument(skip(props), fields(
|
|
|
|
idx=%props.i,
|
|
|
|
title=%props.title.get()
|
|
|
|
))]
|
2022-03-15 18:01:25 -04:00
|
|
|
#[component(RecipeSelection<G>)]
|
|
|
|
pub fn recipe_selection(props: RecipeCheckBoxProps) -> View<G> {
|
2022-08-12 21:41:19 -04:00
|
|
|
let app_service = get_appservice_from_context();
|
2022-03-15 18:01:25 -04:00
|
|
|
// This is total hack but it works around the borrow issues with
|
|
|
|
// the `view!` macro.
|
|
|
|
let i = props.i;
|
|
|
|
let id_as_str = Rc::new(format!("{}", i));
|
|
|
|
let id_cloned_2 = id_as_str.clone();
|
|
|
|
let count = Signal::new(format!("{}", app_service.get_recipe_count_by_index(i)));
|
|
|
|
view! {
|
2022-03-23 20:26:58 -04:00
|
|
|
div() {
|
2022-07-21 16:33:55 -04:00
|
|
|
label(for=id_cloned_2) { a(href=format!("#recipe/{}", i)) { (props.title.get()) } }
|
2022-03-15 18:01:25 -04:00
|
|
|
input(type="number", class="item-count-sel", 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();
|
2022-07-20 17:58:44 -04:00
|
|
|
debug!(idx=%i, count=%(*count.get()), "setting recipe count");
|
2022-03-15 18:01:25 -04:00
|
|
|
app_service.set_recipe_count_by_index(i, count.get().parse().unwrap());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|