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