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:
2
backend/migrations/005_add_last_used_calendar.sql
Normal file
2
backend/migrations/005_add_last_used_calendar.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
-- Add last used calendar preference to user preferences
|
||||
ALTER TABLE user_preferences ADD COLUMN last_used_calendar TEXT;
|
||||
@@ -93,6 +93,7 @@ impl AuthService {
|
||||
calendar_theme: preferences.calendar_theme,
|
||||
calendar_style: preferences.calendar_style,
|
||||
calendar_colors: preferences.calendar_colors,
|
||||
last_used_calendar: preferences.last_used_calendar,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ pub struct UserPreferences {
|
||||
pub calendar_theme: Option<String>,
|
||||
pub calendar_style: Option<String>,
|
||||
pub calendar_colors: Option<String>, // JSON string
|
||||
pub last_used_calendar: Option<String>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
@@ -109,6 +110,7 @@ impl UserPreferences {
|
||||
calendar_theme: Some("light".to_string()),
|
||||
calendar_style: Some("default".to_string()),
|
||||
calendar_colors: None,
|
||||
last_used_calendar: None,
|
||||
updated_at: Utc::now(),
|
||||
}
|
||||
}
|
||||
@@ -266,8 +268,8 @@ impl<'a> PreferencesRepository<'a> {
|
||||
sqlx::query(
|
||||
"INSERT INTO user_preferences
|
||||
(user_id, calendar_selected_date, calendar_time_increment,
|
||||
calendar_view_mode, calendar_theme, calendar_style, calendar_colors, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
calendar_view_mode, calendar_theme, calendar_style, calendar_colors, last_used_calendar, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
)
|
||||
.bind(&prefs.user_id)
|
||||
.bind(&prefs.calendar_selected_date)
|
||||
@@ -276,6 +278,7 @@ impl<'a> PreferencesRepository<'a> {
|
||||
.bind(&prefs.calendar_theme)
|
||||
.bind(&prefs.calendar_style)
|
||||
.bind(&prefs.calendar_colors)
|
||||
.bind(&prefs.last_used_calendar)
|
||||
.bind(&prefs.updated_at)
|
||||
.execute(self.db.pool())
|
||||
.await?;
|
||||
@@ -290,7 +293,7 @@ impl<'a> PreferencesRepository<'a> {
|
||||
"UPDATE user_preferences
|
||||
SET calendar_selected_date = ?, calendar_time_increment = ?,
|
||||
calendar_view_mode = ?, calendar_theme = ?, calendar_style = ?,
|
||||
calendar_colors = ?, updated_at = ?
|
||||
calendar_colors = ?, last_used_calendar = ?, updated_at = ?
|
||||
WHERE user_id = ?",
|
||||
)
|
||||
.bind(&prefs.calendar_selected_date)
|
||||
@@ -299,6 +302,7 @@ impl<'a> PreferencesRepository<'a> {
|
||||
.bind(&prefs.calendar_theme)
|
||||
.bind(&prefs.calendar_style)
|
||||
.bind(&prefs.calendar_colors)
|
||||
.bind(&prefs.last_used_calendar)
|
||||
.bind(Utc::now())
|
||||
.bind(&prefs.user_id)
|
||||
.execute(self.db.pool())
|
||||
|
||||
@@ -40,6 +40,7 @@ pub async fn get_preferences(
|
||||
calendar_theme: preferences.calendar_theme,
|
||||
calendar_style: preferences.calendar_style,
|
||||
calendar_colors: preferences.calendar_colors,
|
||||
last_used_calendar: preferences.last_used_calendar,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -85,6 +86,9 @@ pub async fn update_preferences(
|
||||
if request.calendar_colors.is_some() {
|
||||
preferences.calendar_colors = request.calendar_colors;
|
||||
}
|
||||
if request.last_used_calendar.is_some() {
|
||||
preferences.last_used_calendar = request.last_used_calendar;
|
||||
}
|
||||
|
||||
prefs_repo
|
||||
.update(&preferences)
|
||||
@@ -100,6 +104,7 @@ pub async fn update_preferences(
|
||||
calendar_theme: preferences.calendar_theme,
|
||||
calendar_style: preferences.calendar_style,
|
||||
calendar_colors: preferences.calendar_colors,
|
||||
last_used_calendar: preferences.last_used_calendar,
|
||||
}),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ pub struct UserPreferencesResponse {
|
||||
pub calendar_theme: Option<String>,
|
||||
pub calendar_style: Option<String>,
|
||||
pub calendar_colors: Option<String>,
|
||||
pub last_used_calendar: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
@@ -40,6 +41,7 @@ pub struct UpdatePreferencesRequest {
|
||||
pub calendar_theme: Option<String>,
|
||||
pub calendar_style: Option<String>,
|
||||
pub calendar_colors: Option<String>,
|
||||
pub last_used_calendar: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
|
||||
Reference in New Issue
Block a user