swadhinbiswas feat: new feacture added · 8/31/2026
6500ca6
170 lines · 3.9 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// User Progress & Data Types

export interface UserProgress {
  totalTopicsCompleted: number;
  topicsBySection: Record<string, number>;
  studyStreak: number;
  lastStudyDate: string | null;
  totalStudyTime: number; // in minutes
  sessionsLog: StudySession[];
  achievements: Achievement[];
}

export interface StudySession {
  id: string;
  date: string;
  duration: number; // minutes
  topic: string;
  section: string;
}

export interface Achievement {
  id: string;
  name: string;
  description: string;
  icon: string;
  unlockedAt: string;
}

export interface InterviewQuestion {
  id: string;
  title: string;
  company: string;
  role: string;
  type: 'coding' | 'system-design' | 'behavioral' | 'sql';
  difficulty: 'easy' | 'medium' | 'hard';
  question: string;
  solution?: string;
  hints: string[];
  tags: string[];
  leetCodeLink?: string;
  timesAsked: number;
  userRating?: number;
  userNotes?: string;
  solved: boolean;
  solvedAt?: string;
  attempts: number;
}

export interface JobApplication {
  id: string;
  company: string;
  role: string;
  status: 'researching' | 'applied' | 'screening' | 'interview' | 'offer' | 'rejected' | 'withdrawn';
  dateApplied: string;
  location: string;
  jobUrl?: string;
  referral?: string;
  salaryRange?: string;
  notes: string;
  interviews: InterviewRound[];
  createdAt: string;
  updatedAt: string;
}

export interface InterviewRound {
  id: string;
  type: string;
  date: string;
  feedback?: string;
  rating?: number;
}

export interface StudyPlan {
  id: string;
  name: string;
  targetCompanies: string[];
  targetRole: string;
  weeks: number;
  hoursPerWeek: number;
  startDate: string;
  endDate: string;
  topics: StudyTopic[];
  progress: number;
  createdAt: string;
}

export interface StudyTopic {
  id: string;
  name: string;
  section: string;
  estimatedHours: number;
  completed: boolean;
  completedAt?: string;
  resources: string[];
}

// Storage Keys
export const STORAGE_KEYS = {
  PROGRESS: 'faang-progress',
  QUESTIONS: 'faang-questions',
  APPLICATIONS: 'faang-applications',
  STUDY_PLANS: 'faang-study-plans',
  SETTINGS: 'faang-settings',
};

// Helper Functions
export function saveToStorage<T>(key: string, data: T): void {
  try {
    localStorage.setItem(key, JSON.stringify(data));
  } catch (error) {
    console.error('Error saving to localStorage:', error);
  }
}

export function loadFromStorage<T>(key: string): T | null {
  try {
    const data = localStorage.getItem(key);
    return data ? JSON.parse(data) : null;
  } catch (error) {
    console.error('Error loading from localStorage:', error);
    return null;
  }
}

export function generateId(): string {
  return Date.now().toString(36) + Math.random().toString(36).substr(2);
}

export function formatDate(date: Date): string {
  return date.toISOString().split('T')[0];
}

export function getDaysBetween(date1: string, date2: string): number {
  const d1 = new Date(date1);
  const d2 = new Date(date2);
  const diffTime = Math.abs(d2.getTime() - d1.getTime());
  return Math.ceil(diffTime / (1000 * 60 * 60 * 24));
}

// Initialize default data
export function initializeStorage(): void {
  // Initialize progress
  if (!loadFromStorage(STORAGE_KEYS.PROGRESS)) {
    saveToStorage(STORAGE_KEYS.PROGRESS, {
      totalTopicsCompleted: 0,
      topicsBySection: {},
      studyStreak: 0,
      lastStudyDate: null,
      totalStudyTime: 0,
      sessionsLog: [],
      achievements: [],
    } as UserProgress);
  }

  // Initialize questions
  if (!loadFromStorage(STORAGE_KEYS.QUESTIONS)) {
    saveToStorage(STORAGE_KEYS.QUESTIONS, [] as InterviewQuestion[]);
  }

  // Initialize applications
  if (!loadFromStorage(STORAGE_KEYS.APPLICATIONS)) {
    saveToStorage(STORAGE_KEYS.APPLICATIONS, [] as JobApplication[]);
  }

  // Initialize study plans
  if (!loadFromStorage(STORAGE_KEYS.STUDY_PLANS)) {
    saveToStorage(STORAGE_KEYS.STUDY_PLANS, [] as StudyPlan[]);
  }
}