File tree Expand file tree Collapse file tree 2 files changed +10
-8
lines changed
Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change 11import { createDefaultTimetable } from '../utils/timetableHelpers' ;
2- import { lightTheme , themes } from './theme' ;
2+ import { themes } from './theme' ;
33
44const 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments