@@ -98,93 +98,17 @@ export const assignDefaultsToUserData = (data: object): UserData => {
98
98
} ;
99
99
} ;
100
100
101
+ // localstorage key for theme. We need this to set light / dark theme the moment the page loads.
102
+ // duplicated from guide:userData:v100.
103
+ export const themeKey = 'guide:userData:theme' ;
104
+
101
105
// Todo figure out why we even need defaults
102
106
const UserDataContext = createContext < UserDataContextAPI > ( {
103
- // make suer CREATING_ACCOUNT_FOR_FIRST_TIME is here
104
107
userData : assignDefaultsToUserData ( { } ) ,
105
108
updateUserData : _ => { } ,
106
109
signOut : ( ) => Promise . resolve ( ) ,
107
110
firebaseUser : null ,
108
- // firebaseUser: null,
109
- // getDataExport: () => Promise.resolve(),
110
- // importUserData: () => true,
111
- // showTags: false,
112
- // hideDifficulty: false,
113
- // hideModules: false,
114
- // divisionTableQuery: {
115
- // division: '',
116
- // season: '',
117
- // },
118
111
isLoaded : true ,
119
- // lang: 'cpp',
120
- // lastReadAnnouncement: 'open-source',
121
- // lastViewedModule: 'binary-search-sorted',
122
- // lastVisitDate: 1608324157466,
123
- // numPageviews: 130,
124
- // onlineUsers: -1,
125
- // pageviewsPerDay: {
126
- // 1606896000000: 4,
127
- // 1607068800000: 17,
128
- // 1608192000000: 27,
129
- // 1608278400000: 82,
130
- // },
131
- // theme: 'system',
132
- // setTheme: _x => {
133
- // // do nothing
134
- // },
135
- // setShowTags: _x => {
136
- // // do nothing
137
- // },
138
- // setHideDifficulty: _x => {
139
- // // do nothing
140
- // },
141
- // setHideModules: _x => {
142
- // // do nothing
143
- // },
144
- // setDivisionTableQuery: _x => {
145
- // // do nothing
146
- // },
147
- // setLang: _x => {
148
- // // do nothing
149
- // },
150
- // setLastReadAnnouncement: _x => {
151
- // // do nothing
152
- // },
153
- // setLastViewedModule: _x => {
154
- // // do nothing
155
- // },
156
- // setLastVisitDate: _x => {
157
- // // do nothing
158
- // },
159
- // setModuleProgress: (_moduleID, _progress) => {
160
- // // do nothing/
161
- // },
162
- // setShowIgnored: _x => {
163
- // // do nothing
164
- // },
165
- // setUserProgressOnProblems: (_problemId, _status) => {
166
- // // do nothing
167
- // },
168
- // setUserProgressOnResources: (_moduleId, _status) => {
169
- // // do nothing
170
- // },
171
- // showIgnored: false,
172
- // signOut: () => {
173
- // // do nothing
174
- // return Promise.resolve();
175
- // },
176
- // triggerUserDataContextRerender: () => {},
177
- // userProgressOnModules: {},
178
- // userProgressOnModulesActivity: [],
179
- // userProgressOnProblems: {},
180
- // userProgressOnProblemsActivity: [],
181
- // userProgressOnResources: {},
182
- // adSettings: {
183
- // hideMarch2021: false,
184
- // },
185
- // setAdSettings: () => {
186
- // // do nothing
187
- // },
188
112
} ) ;
189
113
190
114
export const UserDataProvider = ( {
@@ -199,6 +123,9 @@ export const UserDataProvider = ({
199
123
if ( updates . lang && prevState . lang !== updates . lang ) {
200
124
updateLangURL ( updates . lang ) ;
201
125
}
126
+ if ( updates . theme && prevState . theme !== updates . theme ) {
127
+ localStorage . setItem ( themeKey , JSON . stringify ( updates . theme ) ) ;
128
+ }
202
129
return { ...prevState , ...updates } ;
203
130
} ,
204
131
null ,
@@ -387,6 +314,7 @@ export const UserDataProvider = ({
387
314
// // );
388
315
// },
389
316
317
+ // Todo: make sure CREATING_ACCOUNT_FOR_FIRST_TIME is set correctly
390
318
// importUserData: (data: Record<string, any>): boolean => {
391
319
// // if (
392
320
// // confirm(
@@ -436,3 +364,7 @@ export const useUserData = (): UserData => {
436
364
export const useUpdateUserData = ( ) => {
437
365
return React . useContext ( UserDataContext ) . updateUserData ;
438
366
} ;
367
+
368
+ export const useFirebaseUser = ( ) => {
369
+ return React . useContext ( UserDataContext ) . firebaseUser ;
370
+ } ;
0 commit comments