Implement last used calendar tracking with localStorage and database sync

- Add database migration for last_used_calendar field in user preferences
- Update backend models and handlers to support last_used_calendar persistence
- Modify frontend preferences service with update_last_used_calendar() method
- Implement automatic saving of selected calendar on event creation
- Add localStorage fallback for offline usage and immediate UI response
- Update create event modal to default to last used calendar for new events
- Clean up unused imports from event form components

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Connor Johnstone
2025-09-03 16:13:18 -04:00
parent 1e8a8ce5f2
commit dce82d5f7d
11 changed files with 80 additions and 12 deletions

View File

@@ -2,6 +2,7 @@ use crate::components::event_form::*;
use crate::components::EditAction;
use crate::models::ical::VEvent;
use crate::services::calendar_service::CalendarInfo;
use gloo_storage::{LocalStorage, Storage};
use yew::prelude::*;
#[derive(Properties, PartialEq)]
@@ -57,7 +58,25 @@ pub fn create_event_modal(props: &CreateEventModalProps) -> Html {
// Set default calendar
if data.selected_calendar.is_none() && !available_calendars.is_empty() {
data.selected_calendar = Some(available_calendars[0].path.clone());
// For new events, try to use the last used calendar
if event_to_edit.is_none() {
// Try to get last used calendar from localStorage
if let Ok(last_used_calendar) = LocalStorage::get::<String>("last_used_calendar") {
// Check if the last used calendar is still available
if available_calendars.iter().any(|cal| cal.path == last_used_calendar) {
data.selected_calendar = Some(last_used_calendar);
} else {
// Fall back to first available calendar
data.selected_calendar = Some(available_calendars[0].path.clone());
}
} else {
// No last used calendar, use first available
data.selected_calendar = Some(available_calendars[0].path.clone());
}
} else {
// For editing existing events, keep the current calendar as default
data.selected_calendar = Some(available_calendars[0].path.clone());
}
}
// Set edit scope if provided