use crate::models::ical::VEvent; use web_sys::MouseEvent; use yew::prelude::*; #[derive(Clone, PartialEq, Debug)] pub enum DeleteAction { DeleteThis, DeleteFollowing, DeleteSeries, } #[derive(Clone, PartialEq, Debug)] pub enum EditAction { EditThis, EditFuture, EditAll, } #[derive(Properties, PartialEq)] pub struct EventContextMenuProps { pub is_open: bool, pub x: i32, pub y: i32, pub event: Option, pub on_edit: Callback, pub on_delete: Callback, pub on_close: Callback<()>, } #[function_component(EventContextMenu)] pub fn event_context_menu(props: &EventContextMenuProps) -> Html { let menu_ref = use_node_ref(); if !props.is_open { return html! {}; } let style = format!( "position: fixed; left: {}px; top: {}px; z-index: 1001;", props.x, props.y ); // Check if the event is recurring let is_recurring = props .event .as_ref() .map(|event| event.rrule.is_some()) .unwrap_or(false); let create_edit_callback = |action: EditAction| { let on_edit = props.on_edit.clone(); let on_close = props.on_close.clone(); Callback::from(move |_: MouseEvent| { on_edit.emit(action.clone()); on_close.emit(()); }) }; let create_delete_callback = |action: DeleteAction| { let on_delete = props.on_delete.clone(); let on_close = props.on_close.clone(); Callback::from(move |_: MouseEvent| { on_delete.emit(action.clone()); on_close.emit(()); }) }; html! {
{ if is_recurring { html! { <>
{"Edit This Event"}
{"Edit This and Future Events"}
{"Edit All Events in Series"}
} } else { html! {
{"Edit Event"}
} } } { if is_recurring { html! { <>
{"Delete This Event"}
{"Delete Following Events"}
{"Delete Entire Series"}
} } else { html! {
{"Delete Event"}
} } }
} }