Do not display remove buttons for scheduled recipes when picking a date
This commit is contained in:
parent
37721ac3ea
commit
15173c4842
5 changed files with 50 additions and 75 deletions
|
|
@ -57,13 +57,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
// Deactivate recipe links in dialog mode.
|
||||
dialog .calendar .scheduled-recipe {
|
||||
pointer-events: none;
|
||||
cursor: text;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#hidden-templates-calendar {
|
||||
display: none;
|
||||
}
|
||||
|
|
@ -47,6 +47,7 @@
|
|||
</ul>
|
||||
|
||||
<div id="hidden-templates-calendar">
|
||||
<div class="scheduled-recipe"><a></a><span class="remove-scheduled-recipe">X</span></div>
|
||||
<div class="scheduled-recipe-with-link-and-remove"><a></a><span class="remove-scheduled-recipe">X</span></div>
|
||||
<div class="scheduled-recipe"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -1,15 +1,13 @@
|
|||
use std::{cell::RefCell, default, rc::Rc};
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
use chrono::{offset::Local, DateTime, Datelike, Days, Months, NaiveDate, Weekday};
|
||||
use common::ron_api;
|
||||
use chrono::{offset::Local, Datelike, Days, Months, NaiveDate, Weekday};
|
||||
use gloo::{console::log, events::EventListener, utils::document};
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen_futures::spawn_local;
|
||||
use web_sys::Element;
|
||||
|
||||
use crate::{
|
||||
recipe_scheduler::{self, RecipeScheduler},
|
||||
request,
|
||||
recipe_scheduler::RecipeScheduler,
|
||||
utils::{by_id, selector, selector_all, SelectorExt},
|
||||
};
|
||||
|
||||
|
|
@ -60,7 +58,7 @@ impl CalendarState {
|
|||
#[derive(Clone, Copy)]
|
||||
pub struct CalendarOptions {
|
||||
pub can_select_date: bool,
|
||||
// pub show_scheduled_recipes: bool,
|
||||
pub with_link_and_remove: bool,
|
||||
}
|
||||
|
||||
pub fn setup(
|
||||
|
|
@ -104,16 +102,15 @@ pub fn setup(
|
|||
.forget();
|
||||
|
||||
// Click on a day of the current month.
|
||||
if options.can_select_date {
|
||||
let days: Element = calendar.selector(".days");
|
||||
let calendar_clone = calendar.clone();
|
||||
let state_clone = state.clone();
|
||||
EventListener::new(&days, "click", move |event| {
|
||||
let target: Element = event.target().unwrap().dyn_into().unwrap();
|
||||
|
||||
// log!(event);
|
||||
log!(event);
|
||||
|
||||
if target.class_name() == "number" {
|
||||
if target.class_name() == "number" && options.can_select_date {
|
||||
let first_day = first_grid_day(state_clone.get_displayed_date());
|
||||
let day_grid_id = target.parent_element().unwrap().id();
|
||||
let day_offset = day_grid_id[9..10].parse::<u64>().unwrap() * 7
|
||||
|
|
@ -130,7 +127,6 @@ pub fn setup(
|
|||
}
|
||||
})
|
||||
.forget();
|
||||
}
|
||||
|
||||
state
|
||||
}
|
||||
|
|
@ -198,23 +194,7 @@ fn display_month(
|
|||
}
|
||||
|
||||
// Load and display scheduled recipes.
|
||||
// if options.show_scheduled_recipes {
|
||||
spawn_local(async move {
|
||||
// let scheduled_recipes: ron_api::ScheduledRecipes = request::get(
|
||||
// "calendar/get_scheduled_recipes",
|
||||
// [
|
||||
// ("start_date", first_day.date_naive().to_string()),
|
||||
// (
|
||||
// "end_date",
|
||||
// (first_day + Days::new(NB_CALENDAR_ROW * 7))
|
||||
// .date_naive()
|
||||
// .to_string(),
|
||||
// ),
|
||||
// ],
|
||||
// )
|
||||
// .await
|
||||
// .unwrap();
|
||||
|
||||
let scheduled_recipes = recipe_scheduler
|
||||
.get_scheduled_recipes(first_day, first_day + Days::new(NB_CALENDAR_ROW * 7))
|
||||
.await
|
||||
|
|
@ -225,7 +205,11 @@ fn display_month(
|
|||
}
|
||||
|
||||
if !scheduled_recipes.is_empty() {
|
||||
let recipe_template: Element = selector("#hidden-templates-calendar .scheduled-recipe");
|
||||
let recipe_template: Element = if options.with_link_and_remove {
|
||||
selector("#hidden-templates-calendar .scheduled-recipe-with-link-and-remove")
|
||||
} else {
|
||||
selector("#hidden-templates-calendar .scheduled-recipe")
|
||||
};
|
||||
for (date, title, recipe_id) in scheduled_recipes {
|
||||
let id = format!("scheduled-recipe-{}-{}", recipe_id, date);
|
||||
if document().get_element_by_id(&id).is_some() {
|
||||
|
|
@ -245,34 +229,29 @@ fn display_month(
|
|||
.unwrap();
|
||||
recipe_element.set_id(&id);
|
||||
|
||||
let recipe_link_element: Element = recipe_element.selector("a");
|
||||
|
||||
// let recipe_remove_element: Element =
|
||||
// recipe_element.selector(".remove-scheduled-recipe");
|
||||
//
|
||||
// EventListener::new(&recipe_remove_element, "click", move |_event| {
|
||||
// log!("CLICK REMOVE");
|
||||
// })
|
||||
// .forget();
|
||||
|
||||
recipe_link_element
|
||||
.set_attribute("href", &format!("/recipe/view/{}", recipe_id))
|
||||
.unwrap();
|
||||
|
||||
recipe_link_element.set_inner_html(&title);
|
||||
scheduled_recipes_element
|
||||
.append_child(&recipe_element)
|
||||
.unwrap();
|
||||
|
||||
// log!(&title);
|
||||
// TODO
|
||||
let recipe_link_element: Element = if options.with_link_and_remove {
|
||||
recipe_element.selector("a")
|
||||
} else {
|
||||
recipe_element
|
||||
};
|
||||
|
||||
if options.with_link_and_remove {
|
||||
recipe_link_element
|
||||
.set_attribute("href", &format!("/recipe/view/{}", recipe_id))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
recipe_link_element.set_inner_html(&title);
|
||||
}
|
||||
}
|
||||
});
|
||||
// }
|
||||
}
|
||||
|
||||
pub fn first_grid_day(mut date: NaiveDate) -> NaiveDate {
|
||||
fn first_grid_day(mut date: NaiveDate) -> NaiveDate {
|
||||
while (date - Days::new(1)).month() == date.month() {
|
||||
date = date - Days::new(1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ pub fn setup_page(is_user_logged: bool) -> Result<(), JsValue> {
|
|||
selector(".calendar"),
|
||||
calendar::CalendarOptions {
|
||||
can_select_date: false,
|
||||
with_link_and_remove: true,
|
||||
},
|
||||
recipe_scheduler,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ pub fn setup_page(recipe_id: i64, is_user_logged: bool) -> Result<(), JsValue> {
|
|||
element.selector(".calendar"),
|
||||
calendar::CalendarOptions {
|
||||
can_select_date: true,
|
||||
with_link_and_remove: false,
|
||||
},
|
||||
recipe_scheduler,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue