Ingredients can now be added to shopping list when a recipe is scheduled

This commit is contained in:
Greg Burri 2025-02-10 15:02:20 +01:00
parent 15173c4842
commit ce3821b94e
12 changed files with 98 additions and 39 deletions

View file

@ -115,10 +115,10 @@ impl RecipeScheduler {
recipe_id: i64,
date: NaiveDate,
servings: u32,
add_ingredients_to_shopping_list: bool,
) -> Result<ScheduleRecipeResult> {
if self.is_local {
// storage.get(format("scheduled_recipes-{}-{}", )
// storage.set("asd", "hello").unwrap();
// TODO: use 'add_ingredients_to_shopping_list'.
let mut recipe_ids_and_dates = load_scheduled_recipes(date.year(), date.month0());
for recipe in recipe_ids_and_dates.iter() {
if recipe.recipe_id == recipe_id && recipe.date == date {
@ -135,6 +135,7 @@ impl RecipeScheduler {
recipe_id,
date,
servings,
add_ingredients_to_shopping_list,
},
)
.await

View file

@ -21,30 +21,37 @@ pub fn setup_page(recipe_id: i64, is_user_logged: bool) -> Result<(), JsValue> {
EventListener::new(&add_to_planner, "click", move |_event| {
spawn_local(async move {
if let Some((date, servings)) = modal_dialog::show_and_initialize_with_ok(
"#hidden-templates .date-and-servings",
async |element| {
calendar::setup(
element.selector(".calendar"),
calendar::CalendarOptions {
can_select_date: true,
with_link_and_remove: false,
},
recipe_scheduler,
)
},
|element, calendar_state| {
let servings_element: HtmlInputElement = element.selector("#input-servings");
(
calendar_state.get_selected_date(),
servings_element.value_as_number() as u32,
)
},
)
.await
if let Some((date, servings, add_ingredients_to_shopping_list)) =
modal_dialog::show_and_initialize_with_ok(
"#hidden-templates .date-and-servings",
async |element| {
calendar::setup(
element.selector(".calendar"),
calendar::CalendarOptions {
can_select_date: true,
with_link_and_remove: false,
},
recipe_scheduler,
)
},
|element, calendar_state| {
let servings_element: HtmlInputElement =
element.selector("#input-servings");
let add_ingredients_element: HtmlInputElement =
element.selector("#input-add-ingredients-to-shopping-list");
(
calendar_state.get_selected_date(),
servings_element.value_as_number() as u32,
add_ingredients_element.checked(),
)
},
)
.await
{
if let Ok(result) = recipe_scheduler
.shedule_recipe(recipe_id, date, servings)
.shedule_recipe(recipe_id, date, servings, add_ingredients_to_shopping_list)
.await
{
toast::show_element_and_initialize(