Merge branch 'master' of ssh://git.gburri.org:9851/gburri/recipes

This commit is contained in:
Greg Burri 2025-05-26 00:21:55 +02:00
commit 4c6f39b61f

View file

@ -1,14 +1,14 @@
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, rc::Rc};
use chrono::{Datelike, Days, Months, NaiveDate, Weekday, offset::Local}; use chrono::{Datelike, Days, Months, NaiveDate, Weekday, offset::Local};
use common::{web_api, utils::substitute_with_names}; use common::{utils::substitute_with_names, web_api};
use gloo::{ use gloo::{
events::EventListener, events::EventListener,
utils::{document, window}, utils::{document, window},
}; };
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::spawn_local; use wasm_bindgen_futures::spawn_local;
use web_sys::{Element, HtmlInputElement}; use web_sys::{Element, HtmlInputElement, KeyboardEvent};
use crate::{ use crate::{
modal_dialog, modal_dialog,
@ -94,6 +94,32 @@ pub fn setup(
}) })
.forget(); .forget();
// Left arrow key.
let calendar_clone = calendar.clone();
let state_clone = state.clone();
EventListener::new(&document(), "keydown", move |event| {
let key_event: &KeyboardEvent = event.dyn_ref().unwrap();
// Avoid triggering when an input has focus.
if key_event
.target()
.unwrap()
.dyn_ref::<HtmlInputElement>()
.is_some()
{
return;
}
if key_event.key() == "ArrowLeft" {
state_clone.displayed_date_previous_month();
display_month(
&calendar_clone,
state_clone.clone(),
options,
recipe_scheduler,
);
}
})
.forget();
// Click on next month. // Click on next month.
let calendar_clone = calendar.clone(); let calendar_clone = calendar.clone();
let state_clone = state.clone(); let state_clone = state.clone();
@ -108,6 +134,32 @@ pub fn setup(
}) })
.forget(); .forget();
// Right arrow key.
let calendar_clone = calendar.clone();
let state_clone = state.clone();
EventListener::new(&document(), "keydown", move |event| {
let key_event: &KeyboardEvent = event.dyn_ref().unwrap();
// Avoid triggering when an input has focus.
if key_event
.target()
.unwrap()
.dyn_ref::<HtmlInputElement>()
.is_some()
{
return;
}
if key_event.key() == "ArrowRight" {
state_clone.displayed_date_next_month();
display_month(
&calendar_clone,
state_clone.clone(),
options,
recipe_scheduler,
);
}
})
.forget();
// Click on a day of the current month. // Click on a day of the current month.
let days: Element = calendar.selector(".days"); let days: Element = calendar.selector(".days");
let calendar_clone = calendar.clone(); let calendar_clone = calendar.clone();
@ -172,9 +224,11 @@ pub fn setup(
date, date,
remove_ingredients_from_shopping_list, remove_ingredients_from_shopping_list,
}; };
let _ = let _ = ron_request::delete::<(), _>(
ron_request::delete::<(), _>("/ron-api/calendar/scheduled_recipe", Some(body)) "/ron-api/calendar/scheduled_recipe",
.await; Some(body),
)
.await;
window().location().reload().unwrap(); window().location().reload().unwrap();
} }
}); });