Skip to content

Commit a587040

Browse files
authored
Fix the migration error with checkers (#1006)
* fix the migration error with checking user is not new user with proper data * fix edge case of no timetables key on data
1 parent 753fb31 commit a587040

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

client/src/constants/defaults.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { createDefaultTimetable } from '../utils/timetableHelpers';
2-
import { lightTheme, themes } from './theme';
2+
import { themes } from './theme';
33

44
const defaults: Record<string, any> = {
5-
themeObject: lightTheme(Object.keys(themes)[0]),
65
currentTheme: Object.keys(themes)[0],
76
is12HourMode: true,
87
isDarkMode: window.matchMedia('(prefers-color-scheme: dark)').matches,
@@ -13,7 +12,7 @@ const defaults: Record<string, any> = {
1312
isHideExamClasses: false,
1413
isConvertToLocalTimezone: false,
1514
courseData: { map: [] },
16-
timetables: { T0: createDefaultTimetable('') },
15+
timetables: [...createDefaultTimetable('')],
1716
version: 1,
1817
};
1918

client/src/utils/storage.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ const storage = {
8080

8181
if (localStorage[STORAGE_KEY]) {
8282
data = JSON.parse(localStorage[STORAGE_KEY]);
83-
// migrate old data format to new format
84-
data = storage.migrate(data);
83+
// migrate old data format to new format when the app is already visited
84+
if (localStorage['visited']) {
85+
data = storage.migrate(data);
86+
}
8587
} else {
8688
storage.save(data);
8789
}
@@ -94,9 +96,10 @@ const storage = {
9496
},
9597

9698
migrate: (data: Record<string, any>) => {
97-
// User has never seen Notangles
98-
if (!data || typeof data !== 'object') {
99-
data = defaults;
99+
// Check if data is empty or not an object or it is {}
100+
if (!data || typeof data !== 'object' || Object.keys(data).length === 0 || data.timetables === undefined) {
101+
storage.save(defaults);
102+
return defaults;
100103
}
101104

102105
// only do this if version does not exist

0 commit comments

Comments
 (0)