Skip to content

Commit 01de7ec

Browse files
committed
feat: enhance session management with localStorage support for saving and loading sessions
1 parent 632ce37 commit 01de7ec

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

src/managers/navigation-manager.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,14 +1168,10 @@ export class NavigationManager {
11681168

11691169
// Save changes if using SessionManager
11701170
if (window.sessionManager && !session.isHistorical) {
1171-
// Update the session in SessionManager
1172-
const dateString = this.currentDate.toDateString();
1173-
if (window.sessionManager.sessions[dateString]) {
1174-
const sessionIndex = window.sessionManager.sessions[dateString].findIndex(s => s.id === session.id);
1175-
if (sessionIndex !== -1) {
1176-
window.sessionManager.sessions[dateString][sessionIndex] = { ...session };
1177-
}
1178-
}
1171+
// Set the selected date for SessionManager
1172+
window.sessionManager.selectedDate = this.currentDate;
1173+
// Use the proper updateSession method to ensure persistence
1174+
window.sessionManager.updateSession(session);
11791175
}
11801176
}
11811177

src/managers/session-manager.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,34 @@ export class SessionManager {
1111
}
1212

1313
init() {
14+
this.loadSessionsFromStorage();
1415
this.setupEventListeners();
1516
}
1617

18+
// Load sessions from localStorage
19+
loadSessionsFromStorage() {
20+
try {
21+
const savedSessions = localStorage.getItem('presto_manual_sessions');
22+
if (savedSessions) {
23+
this.sessions = JSON.parse(savedSessions);
24+
console.log('Loaded', this.sessions.length, 'manual sessions from storage');
25+
}
26+
} catch (error) {
27+
console.error('Error loading sessions from storage:', error);
28+
this.sessions = [];
29+
}
30+
}
31+
32+
// Save sessions to localStorage
33+
saveSessionsToStorage() {
34+
try {
35+
localStorage.setItem('presto_manual_sessions', JSON.stringify(this.sessions));
36+
console.log('Saved', this.sessions.length, 'manual sessions to storage');
37+
} catch (error) {
38+
console.error('Error saving sessions to storage:', error);
39+
}
40+
}
41+
1742
setupEventListeners() {
1843
// Add session button
1944
const addSessionBtn = document.getElementById('add-session-btn');
@@ -220,6 +245,9 @@ export class SessionManager {
220245
}
221246

222247
this.sessions[dateString].push(sessionData);
248+
249+
// Save to localStorage
250+
this.saveSessionsToStorage();
223251

224252
// TODO: Call backend when available
225253
// await invoke('add_session', { date: dateString, session: sessionData });
@@ -236,6 +264,9 @@ export class SessionManager {
236264
}
237265
}
238266

267+
// Save to localStorage
268+
this.saveSessionsToStorage();
269+
239270
// TODO: Call backend when available
240271
// await invoke('update_session', { date: dateString, sessionId: sessionData.id, updatedSession: sessionData });
241272
}
@@ -253,6 +284,9 @@ export class SessionManager {
253284
this.sessions[dateString] = this.sessions[dateString].filter(s => s.id !== this.currentEditingSession.id);
254285
}
255286

287+
// Save to localStorage
288+
this.saveSessionsToStorage();
289+
256290
// TODO: Call backend when available
257291
// await invoke('delete_session', { date: dateString, sessionId: this.currentEditingSession.id });
258292

0 commit comments

Comments
 (0)