forked from Dhanushsai0407/Vi-Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSessionService.ts
More file actions
35 lines (31 loc) · 1.1 KB
/
SessionService.ts
File metadata and controls
35 lines (31 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import type { AnalysisResult } from './AnalysisEngine';
export interface SavedSession {
id: string;
userId: string;
date: number;
text: string;
analysis: AnalysisResult;
}
export class SessionService {
private static KEY = 'vi_notes_sessions';
static getSessions(userId: string): SavedSession[] {
const all = localStorage.getItem(this.KEY);
if (!all) return [];
const sessions: SavedSession[] = JSON.parse(all);
return sessions.filter((s: SavedSession) => s.userId === userId).sort((a: SavedSession, b: SavedSession) => b.date - a.date);
}
static saveSession(userId: string, text: string, analysis: AnalysisResult): SavedSession {
const all = localStorage.getItem(this.KEY);
const sessions: SavedSession[] = all ? JSON.parse(all) : [];
const session: SavedSession = {
id: crypto.randomUUID(),
userId,
date: Date.now(),
text,
analysis
};
sessions.push(session);
localStorage.setItem(this.KEY, JSON.stringify(sessions));
return session;
}
}