Ingredients can now be remove from shopping list when a recipe is unscheduled.

This commit is contained in:
Greg Burri 2025-02-12 02:05:38 +01:00
parent a3f2b4a86a
commit da5ea57787
7 changed files with 92 additions and 36 deletions

View file

@ -2,11 +2,15 @@ use std::{cell::RefCell, rc::Rc};
use chrono::{offset::Local, Datelike, Days, Months, NaiveDate, Weekday};
use common::{ron_api, utils::substitute_with_names};
use gloo::{console::log, events::EventListener, utils::document};
use gloo::{
console::log,
events::EventListener,
utils::{document, window},
};
use scanf::sscanf;
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::spawn_local;
use web_sys::Element;
use web_sys::{Element, HtmlInputElement};
use crate::{
modal_dialog,
@ -140,31 +144,41 @@ pub fn setup(
let title = target.previous_element_sibling().unwrap().inner_html();
if modal_dialog::show_and_initialize(
"#hidden-templates-calendar .unschedule-confirmation",
async |element| {
let date_format =
selector::<Element>("#hidden-templates-calendar .calendar-date-format")
.inner_html();
element.set_inner_html(&substitute_with_names(
&element.inner_html(),
&["{title}", "{date}"],
&[
&title,
&date
.format_localized(&date_format, get_locale())
.to_string(),
],
));
},
)
.await
.is_some()
if let Some(remove_ingredients_from_shopping_list) =
modal_dialog::show_and_initialize_with_ok(
"#hidden-templates-calendar .unschedule-confirmation",
async |element| {
let date_format = selector::<Element>(
"#hidden-templates-calendar .calendar-date-format",
)
.inner_html();
element.set_inner_html(&substitute_with_names(
&element.inner_html(),
&["{title}", "{date}"],
&[
&title,
&date
.format_localized(&date_format, get_locale())
.to_string(),
],
));
},
|element, _| {
let remove_ingredients_element: HtmlInputElement =
element.selector("#input-remove-ingredients-from-shopping-list");
remove_ingredients_element.checked()
},
)
.await
{
let body = ron_api::ScheduledRecipe { recipe_id, date };
let body = ron_api::RemoveScheduledRecipe {
recipe_id,
date,
remove_ingredients_from_shopping_list,
};
let _ =
request::delete::<(), _>("calendar/remove_scheduled_recipe", body).await;
target.parent_element().unwrap().remove();
window().location().reload().unwrap();
}
});
}