MCPcopy Create free account
hub / github.com/JunJD/alading / InterviewStateManager

Class InterviewStateManager

src/utils/interviewStateManager.ts:13–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11}
12
13export class InterviewStateManager {
14 private static instance: InterviewStateManager;
15
16 private constructor() {}
17
18 static getInstance(): InterviewStateManager {
19 if (!this.instance) {
20 this.instance = new InterviewStateManager();
21 }
22 return this.instance;
23 }
24
25 saveState(config: InterviewConfig) {
26 const state: StoredInterviewState = {
27 type: config.type.id,
28 industry: config.industry?.id || '',
29 resume: config.resume,
30 timestamp: Date.now()
31 };
32
33 try {
34 localStorage.setItem(STORAGE_KEY, JSON.stringify(state));
35 } catch (error) {
36 console.error('Failed to save interview state:', error);
37 }
38 }
39
40 loadState(): StoredInterviewState | null {
41 try {
42 const stored = localStorage.getItem(STORAGE_KEY);
43 if (!stored) return null;
44
45 const state = JSON.parse(stored) as StoredInterviewState;
46
47 // 可以添加状态过期检查,比如24小时后过期
48 const ONE_DAY = 24 * 60 * 60 * 1000;
49 if (Date.now() - state.timestamp > ONE_DAY) {
50 this.clearState();
51 return null;
52 }
53
54 return state;
55 } catch (error) {
56 console.error('Failed to load interview state:', error);
57 return null;
58 }
59 }
60
61 clearState() {
62 try {
63 localStorage.removeItem(STORAGE_KEY);
64 } catch (error) {
65 console.error('Failed to clear interview state:', error);
66 }
67 }
68
69 updateResume(resume: ResumeInfo) {
70 const currentState = this.loadState();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected