Fix event calendar change to use delete + create instead of update

When changing an event's calendar, the system now properly handles this as:
- Delete the event from the original calendar
- Create a new event in the target calendar

This ensures proper CalDAV compliance and prevents issues with cross-calendar updates.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Connor Johnstone
2025-08-29 11:47:45 -04:00
parent 508c4f129f
commit edb216347d

View File

@@ -705,37 +705,108 @@ pub fn App() -> Html {
_ => "none",
}.to_string();
match calendar_service.update_event(
&token,
&password,
original_event.uid,
updated_data.title,
updated_data.description,
start_date,
start_time,
end_date,
end_time,
updated_data.location,
updated_data.all_day,
status_str,
class_str,
updated_data.priority,
updated_data.organizer,
updated_data.attendees,
updated_data.categories,
reminder_str,
recurrence_str,
updated_data.recurrence_days,
updated_data.selected_calendar
).await {
Ok(_) => {
web_sys::console::log_1(&"Event updated successfully".into());
// Trigger a page reload to refresh events from all calendars
web_sys::window().unwrap().location().reload().unwrap();
// Check if the calendar has changed
let calendar_changed = original_event.calendar_path.as_ref() != updated_data.selected_calendar.as_ref();
if calendar_changed {
// Calendar changed - need to delete from original and create in new
web_sys::console::log_1(&"Calendar changed - performing delete + create".into());
// First delete from original calendar
if let Some(original_calendar_path) = &original_event.calendar_path {
if let Some(event_href) = &original_event.href {
match calendar_service.delete_event(
&token,
&password,
original_calendar_path.clone(),
event_href.clone(),
"single".to_string(), // delete single occurrence
None
).await {
Ok(_) => {
web_sys::console::log_1(&"Original event deleted successfully".into());
// Now create the event in the new calendar
match calendar_service.create_event(
&token,
&password,
updated_data.title,
updated_data.description,
start_date,
start_time,
end_date,
end_time,
updated_data.location,
updated_data.all_day,
status_str,
class_str,
updated_data.priority,
updated_data.organizer,
updated_data.attendees,
updated_data.categories,
reminder_str,
recurrence_str,
updated_data.recurrence_days,
updated_data.selected_calendar
).await {
Ok(_) => {
web_sys::console::log_1(&"Event moved to new calendar successfully".into());
// Trigger a page reload to refresh events from all calendars
web_sys::window().unwrap().location().reload().unwrap();
}
Err(err) => {
web_sys::console::error_1(&format!("Failed to create event in new calendar: {}", err).into());
web_sys::window().unwrap().alert_with_message(&format!("Failed to move event to new calendar: {}", err)).unwrap();
}
}
}
Err(err) => {
web_sys::console::error_1(&format!("Failed to delete original event: {}", err).into());
web_sys::window().unwrap().alert_with_message(&format!("Failed to delete original event: {}", err)).unwrap();
}
}
} else {
web_sys::console::error_1(&"Original event missing href for deletion".into());
web_sys::window().unwrap().alert_with_message("Cannot move event - original event missing href").unwrap();
}
} else {
web_sys::console::error_1(&"Original event missing calendar_path for deletion".into());
web_sys::window().unwrap().alert_with_message("Cannot move event - original event missing calendar path").unwrap();
}
Err(err) => {
web_sys::console::error_1(&format!("Failed to update event: {}", err).into());
web_sys::window().unwrap().alert_with_message(&format!("Failed to update event: {}", err)).unwrap();
} else {
// Calendar hasn't changed - normal update
match calendar_service.update_event(
&token,
&password,
original_event.uid,
updated_data.title,
updated_data.description,
start_date,
start_time,
end_date,
end_time,
updated_data.location,
updated_data.all_day,
status_str,
class_str,
updated_data.priority,
updated_data.organizer,
updated_data.attendees,
updated_data.categories,
reminder_str,
recurrence_str,
updated_data.recurrence_days,
updated_data.selected_calendar
).await {
Ok(_) => {
web_sys::console::log_1(&"Event updated successfully".into());
// Trigger a page reload to refresh events from all calendars
web_sys::window().unwrap().location().reload().unwrap();
}
Err(err) => {
web_sys::console::error_1(&format!("Failed to update event: {}", err).into());
web_sys::window().unwrap().alert_with_message(&format!("Failed to update event: {}", err)).unwrap();
}
}
}
});