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:
@@ -12,6 +12,7 @@ pub struct UserPreferences {
|
||||
pub calendar_view_mode: Option<String>,
|
||||
pub calendar_theme: Option<String>,
|
||||
pub calendar_colors: Option<String>,
|
||||
pub last_used_calendar: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
@@ -22,6 +23,7 @@ pub struct UpdatePreferencesRequest {
|
||||
pub calendar_view_mode: Option<String>,
|
||||
pub calendar_theme: Option<String>,
|
||||
pub calendar_colors: Option<String>,
|
||||
pub last_used_calendar: Option<String>,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
@@ -61,6 +63,7 @@ impl PreferencesService {
|
||||
calendar_view_mode: None,
|
||||
calendar_theme: None,
|
||||
calendar_colors: None,
|
||||
last_used_calendar: None,
|
||||
});
|
||||
|
||||
// Update the specific field
|
||||
@@ -95,6 +98,7 @@ impl PreferencesService {
|
||||
calendar_view_mode: preferences.calendar_view_mode.clone(),
|
||||
calendar_theme: preferences.calendar_theme.clone(),
|
||||
calendar_colors: preferences.calendar_colors.clone(),
|
||||
last_used_calendar: preferences.last_used_calendar.clone(),
|
||||
};
|
||||
|
||||
self.sync_preferences(&session_token, &request).await
|
||||
@@ -156,6 +160,7 @@ impl PreferencesService {
|
||||
calendar_view_mode: LocalStorage::get::<String>("calendar_view_mode").ok(),
|
||||
calendar_theme: LocalStorage::get::<String>("calendar_theme").ok(),
|
||||
calendar_colors: LocalStorage::get::<String>("calendar_colors").ok(),
|
||||
last_used_calendar: LocalStorage::get::<String>("last_used_calendar").ok(),
|
||||
};
|
||||
|
||||
// Only migrate if we have some preferences to migrate
|
||||
@@ -164,6 +169,7 @@ impl PreferencesService {
|
||||
|| request.calendar_view_mode.is_some()
|
||||
|| request.calendar_theme.is_some()
|
||||
|| request.calendar_colors.is_some()
|
||||
|| request.last_used_calendar.is_some()
|
||||
{
|
||||
self.sync_preferences(&session_token, &request).await?;
|
||||
|
||||
@@ -177,4 +183,24 @@ impl PreferencesService {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Update the last used calendar and sync with backend
|
||||
pub async fn update_last_used_calendar(&self, calendar_path: &str) -> Result<(), String> {
|
||||
// Get session token
|
||||
let session_token = LocalStorage::get::<String>("session_token")
|
||||
.map_err(|_| "No session token found".to_string())?;
|
||||
|
||||
// Create minimal update request with only the last used calendar
|
||||
let request = UpdatePreferencesRequest {
|
||||
calendar_selected_date: None,
|
||||
calendar_time_increment: None,
|
||||
calendar_view_mode: None,
|
||||
calendar_theme: None,
|
||||
calendar_colors: None,
|
||||
last_used_calendar: Some(calendar_path.to_string()),
|
||||
};
|
||||
|
||||
// Sync to backend
|
||||
self.sync_preferences(&session_token, &request).await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user