@jsb188/react 1.1.10 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +20 -20
- package/states/apiData.ts +18 -16
- package/states/appContext.ts +364 -311
- package/states/connected.ts +135 -11
- package/states/index.ts +1 -1
- package/states/keyDown.ts +32 -27
- package/states/modal.ts +291 -260
- package/states/popOver.ts +268 -229
- package/states/reactiveEvents.ts +56 -0
- package/states/uploads.ts +41 -27
- package/types/PopOver.d.ts +424 -230
- package/utils/hooks.ts +306 -271
- package/utils/schema.ts +144 -132
- package/states/toasts.ts +0 -30
package/states/appContext.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
clearAppCache,
|
|
3
|
+
fetchLightModeSetting,
|
|
4
|
+
isSystemDarkMode,
|
|
5
|
+
saveAuthTokenToPlatform,
|
|
6
|
+
} from '@jsb188/app/platform.ts';
|
|
7
|
+
import type {
|
|
8
|
+
AccountData,
|
|
9
|
+
AccountSettings,
|
|
10
|
+
AuthenticationData,
|
|
11
|
+
LightModeEnum,
|
|
12
|
+
} from '@jsb188/app/types/auth.d.ts';
|
|
3
13
|
import { setAuthToken } from '@jsb188/app/utils/api.ts';
|
|
4
14
|
import { getDisplayName } from '@jsb188/app/utils/string.ts';
|
|
5
15
|
import { createContext, useContext } from 'react';
|
|
@@ -9,21 +19,20 @@ import { createContext, useContext } from 'react';
|
|
|
9
19
|
*/
|
|
10
20
|
|
|
11
21
|
type AppContextAction = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
data?: any;
|
|
22
|
+
__type: // App initialization
|
|
23
|
+
| 'APP_INIT'
|
|
24
|
+
// Auth setup
|
|
25
|
+
| 'APP_LOGIN'
|
|
26
|
+
| 'APP_GUEST'
|
|
27
|
+
| 'APP_REFRESH_AUTH'
|
|
28
|
+
| 'APP_EDIT_AUTH'
|
|
29
|
+
| 'APP_EDIT_ACCOUNT'
|
|
30
|
+
| 'APP_SWITCH_PRIMARY_ORGANIZATION'
|
|
31
|
+
// Account theme
|
|
32
|
+
| 'APP_THEME'
|
|
33
|
+
| 'APP_SYSTEM_LIGHT_MODE'
|
|
34
|
+
| 'APP_LIGHT_MODE';
|
|
35
|
+
data?: any;
|
|
27
36
|
};
|
|
28
37
|
|
|
29
38
|
export type AppContextDispatch = (action: AppContextAction) => void;
|
|
@@ -35,33 +44,34 @@ export type CurrentAccountObj = ReturnType<typeof useCurrentAccount>;
|
|
|
35
44
|
*/
|
|
36
45
|
|
|
37
46
|
export type AppAppearanceType = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
realLightMode: LightModeEnum;
|
|
48
|
+
lightMode: LightModeEnum;
|
|
49
|
+
previewLightMode: LightModeEnum;
|
|
50
|
+
previewTheme: Record<string, any> | null;
|
|
42
51
|
};
|
|
43
52
|
|
|
44
53
|
export type AppContextData = {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
// Required for app
|
|
55
|
+
init: 0 | 1 | 2; // 0 = not initialized,; 1 = loading; 2 = initialized
|
|
56
|
+
authorization: string; // This is token
|
|
57
|
+
networkError: boolean;
|
|
58
|
+
|
|
59
|
+
// Authentication data
|
|
60
|
+
account: AccountData | null;
|
|
61
|
+
primaryOrganizationId: string | null;
|
|
62
|
+
cacheAuthorizationEpoch: string | null;
|
|
63
|
+
|
|
64
|
+
// Account settings & state
|
|
65
|
+
settings: AccountSettings;
|
|
66
|
+
activated: boolean;
|
|
67
|
+
hasPassword: boolean;
|
|
68
|
+
webVersion: string | null;
|
|
69
|
+
alertUpdatesOnMount: boolean;
|
|
70
|
+
|
|
71
|
+
// Preview theme overrides active theme
|
|
72
|
+
systemLightMode: 'LIGHT' | 'DARK';
|
|
73
|
+
previewLightMode: LightModeEnum | null;
|
|
74
|
+
previewTheme: Record<string, any> | null;
|
|
65
75
|
};
|
|
66
76
|
|
|
67
77
|
/**
|
|
@@ -69,29 +79,27 @@ export type AppContextData = {
|
|
|
69
79
|
*/
|
|
70
80
|
|
|
71
81
|
export const DEFAULT_APP_CONTEXT = {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
previewLightMode: null,
|
|
94
|
-
previewTheme: null,
|
|
82
|
+
init: 0,
|
|
83
|
+
authorization: '',
|
|
84
|
+
networkError: false,
|
|
85
|
+
|
|
86
|
+
account: null,
|
|
87
|
+
primaryOrganizationId: null,
|
|
88
|
+
cacheAuthorizationEpoch: null,
|
|
89
|
+
|
|
90
|
+
settings: {
|
|
91
|
+
theme: null,
|
|
92
|
+
lightMode: 'LIGHT',
|
|
93
|
+
timeZone: null,
|
|
94
|
+
},
|
|
95
|
+
activated: false,
|
|
96
|
+
hasPassword: false,
|
|
97
|
+
webVersion: null,
|
|
98
|
+
alertUpdatesOnMount: false,
|
|
99
|
+
|
|
100
|
+
systemLightMode: 'LIGHT',
|
|
101
|
+
previewLightMode: null,
|
|
102
|
+
previewTheme: null,
|
|
95
103
|
} as AppContextData;
|
|
96
104
|
|
|
97
105
|
/**
|
|
@@ -99,32 +107,38 @@ export const DEFAULT_APP_CONTEXT = {
|
|
|
99
107
|
*/
|
|
100
108
|
|
|
101
109
|
function ensureLightModeSetting(lightMode?: LightModeEnum): LightModeEnum {
|
|
102
|
-
|
|
110
|
+
return lightMode && ['LIGHT', 'DARK', 'SYSTEM'].includes(lightMode || '')
|
|
111
|
+
? lightMode
|
|
112
|
+
: 'LIGHT';
|
|
103
113
|
}
|
|
104
114
|
|
|
105
115
|
/**
|
|
106
116
|
* App log in with Promise
|
|
107
117
|
*/
|
|
108
118
|
|
|
109
|
-
export function onAccountLogin(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
119
|
+
export function onAccountLogin(
|
|
120
|
+
auth: any,
|
|
121
|
+
dispatchApp: AppContextDispatch,
|
|
122
|
+
otherCB?: (auth: any) => void,
|
|
123
|
+
) {
|
|
124
|
+
if (auth && auth?.token && auth.activated && auth.account) {
|
|
125
|
+
console.log('.. 🥝 logged into account ..');
|
|
126
|
+
|
|
127
|
+
saveAuthTokenToPlatform(auth.token, () => {
|
|
128
|
+
clearAppCache();
|
|
129
|
+
dispatchApp({
|
|
130
|
+
__type: 'APP_LOGIN',
|
|
131
|
+
data: auth,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
if (otherCB) {
|
|
135
|
+
otherCB(auth);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
} else {
|
|
139
|
+
console.log(auth);
|
|
140
|
+
console.warn('Developer error in onAccountLogin()');
|
|
141
|
+
}
|
|
128
142
|
}
|
|
129
143
|
|
|
130
144
|
/**
|
|
@@ -132,15 +146,15 @@ export function onAccountLogin(auth: any, dispatchApp: AppContextDispatch, other
|
|
|
132
146
|
*/
|
|
133
147
|
|
|
134
148
|
export function onGuestInit(error: any, dispatchApp: AppContextDispatch) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
149
|
+
fetchLightModeSetting(null, (lightMode) => {
|
|
150
|
+
dispatchApp({
|
|
151
|
+
__type: 'APP_GUEST',
|
|
152
|
+
data: {
|
|
153
|
+
error,
|
|
154
|
+
lightMode,
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
});
|
|
144
158
|
}
|
|
145
159
|
|
|
146
160
|
/**
|
|
@@ -148,24 +162,23 @@ export function onGuestInit(error: any, dispatchApp: AppContextDispatch) {
|
|
|
148
162
|
*/
|
|
149
163
|
|
|
150
164
|
export function getTheme(
|
|
151
|
-
|
|
152
|
-
|
|
165
|
+
appState: AppContextData,
|
|
166
|
+
priority: 'PREVIEW' | 'ACCOUNT' | 'ACTIVE',
|
|
153
167
|
) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
};
|
|
168
|
+
let lightMode = appState.previewLightMode || appState.settings.lightMode;
|
|
169
|
+
if (lightMode === 'SYSTEM') {
|
|
170
|
+
lightMode = appState.systemLightMode;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const theme =
|
|
174
|
+
(priority === 'PREVIEW' && appState.previewTheme) ||
|
|
175
|
+
appState.settings.theme ||
|
|
176
|
+
'';
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
lightMode: lightMode || 'LIGHT',
|
|
180
|
+
theme,
|
|
181
|
+
};
|
|
169
182
|
}
|
|
170
183
|
|
|
171
184
|
/**
|
|
@@ -173,17 +186,17 @@ export function getTheme(
|
|
|
173
186
|
*/
|
|
174
187
|
|
|
175
188
|
export function getPreviewAppearance(appState: AppContextData) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
189
|
+
let realLightMode = appState.previewLightMode || appState.settings.lightMode;
|
|
190
|
+
if (realLightMode === 'SYSTEM') {
|
|
191
|
+
realLightMode = appState.systemLightMode;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
realLightMode,
|
|
196
|
+
lightMode: appState.settings.lightMode,
|
|
197
|
+
previewLightMode: appState.previewLightMode,
|
|
198
|
+
previewTheme: appState.previewTheme,
|
|
199
|
+
};
|
|
187
200
|
}
|
|
188
201
|
|
|
189
202
|
/**
|
|
@@ -191,51 +204,52 @@ export function getPreviewAppearance(appState: AppContextData) {
|
|
|
191
204
|
*/
|
|
192
205
|
|
|
193
206
|
export function mergeAuthToDefaultValues(
|
|
194
|
-
|
|
195
|
-
|
|
207
|
+
auth?: AuthenticationData | null,
|
|
208
|
+
authToken?: string | null,
|
|
196
209
|
) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
210
|
+
if (auth?.token && auth?.account?.id) {
|
|
211
|
+
let systemLightMode = 'LIGHT';
|
|
212
|
+
if (isSystemDarkMode()) {
|
|
213
|
+
systemLightMode = 'DARK';
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
setAuthToken(auth.token);
|
|
217
|
+
|
|
218
|
+
const authSettings = {
|
|
219
|
+
...DEFAULT_APP_CONTEXT.settings,
|
|
220
|
+
...auth.account.settings,
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
authSettings.lightMode = ensureLightModeSetting(authSettings.lightMode);
|
|
224
|
+
|
|
225
|
+
return {
|
|
226
|
+
...DEFAULT_APP_CONTEXT,
|
|
227
|
+
init: 1, // Always 1 because we're always using SSR for authentication
|
|
228
|
+
authorization: auth.token,
|
|
229
|
+
account: auth.account,
|
|
230
|
+
primaryOrganizationId: auth.primaryOrganizationId || null,
|
|
231
|
+
cacheAuthorizationEpoch: auth.cacheAuthorizationEpoch || null,
|
|
232
|
+
settings: authSettings,
|
|
233
|
+
|
|
234
|
+
alertUpdatesOnMount: auth.alertUpdatesOnMount,
|
|
235
|
+
hasPassword: auth.hasPassword,
|
|
236
|
+
webVersion: auth.webVersion,
|
|
237
|
+
|
|
238
|
+
// Theme
|
|
239
|
+
systemLightMode,
|
|
240
|
+
previewLightMode: null,
|
|
241
|
+
previewTheme: null,
|
|
242
|
+
};
|
|
243
|
+
} else if (authToken) {
|
|
244
|
+
setAuthToken(authToken);
|
|
245
|
+
return {
|
|
246
|
+
...DEFAULT_APP_CONTEXT,
|
|
247
|
+
authorization: authToken || '',
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
setAuthToken(null);
|
|
252
|
+
return DEFAULT_APP_CONTEXT;
|
|
239
253
|
}
|
|
240
254
|
|
|
241
255
|
/**
|
|
@@ -243,129 +257,152 @@ export function mergeAuthToDefaultValues(
|
|
|
243
257
|
*/
|
|
244
258
|
|
|
245
259
|
export const appReducer = (state: AppContextData, action: AppContextAction) => {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
260
|
+
const { __type, data } = action;
|
|
261
|
+
|
|
262
|
+
switch (__type) {
|
|
263
|
+
case 'APP_INIT': {
|
|
264
|
+
return {
|
|
265
|
+
...state,
|
|
266
|
+
init: state.init === 1 ? 2 : 1,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
case 'APP_LOGIN': {
|
|
270
|
+
return mergeAuthToDefaultValues(data);
|
|
271
|
+
}
|
|
272
|
+
case 'APP_REFRESH_AUTH': {
|
|
273
|
+
const authorization = data?.authorization || '';
|
|
274
|
+
if (!authorization) {
|
|
275
|
+
return state;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
setAuthToken(authorization);
|
|
279
|
+
return {
|
|
280
|
+
...state,
|
|
281
|
+
authorization,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
case 'APP_GUEST': {
|
|
285
|
+
const networkError = data.error?.errorCode === 'network_error';
|
|
286
|
+
if (networkError) {
|
|
287
|
+
console.log('.. ❌ network error ..');
|
|
288
|
+
} else {
|
|
289
|
+
console.log('.. 🥝 guest entered ..');
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
clearAppCache();
|
|
293
|
+
setAuthToken(null);
|
|
294
|
+
|
|
295
|
+
return {
|
|
296
|
+
...DEFAULT_APP_CONTEXT,
|
|
297
|
+
init: 2,
|
|
298
|
+
authorization: '',
|
|
299
|
+
networkError,
|
|
300
|
+
|
|
301
|
+
// Theme
|
|
302
|
+
previewLightMode: null,
|
|
303
|
+
previewTheme: null,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
case 'APP_EDIT_AUTH': {
|
|
307
|
+
if (data.id === state.account?.id) {
|
|
308
|
+
return {
|
|
309
|
+
...state,
|
|
310
|
+
hasPassword:
|
|
311
|
+
typeof data.hasPassword === 'boolean'
|
|
312
|
+
? data.hasPassword
|
|
313
|
+
: state.hasPassword,
|
|
314
|
+
account: !data.email
|
|
315
|
+
? state.account
|
|
316
|
+
: {
|
|
317
|
+
...state.account,
|
|
318
|
+
email: data.email,
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
return state;
|
|
323
|
+
}
|
|
324
|
+
case 'APP_EDIT_ACCOUNT': {
|
|
325
|
+
if (data.id === state.account?.id) {
|
|
326
|
+
return {
|
|
327
|
+
...state,
|
|
328
|
+
|
|
329
|
+
// Account
|
|
330
|
+
account: {
|
|
331
|
+
...state.account,
|
|
332
|
+
...data,
|
|
333
|
+
plus: !data.plus
|
|
334
|
+
? state.account?.plus
|
|
335
|
+
: {
|
|
336
|
+
...state.account?.plus,
|
|
337
|
+
...data.plus,
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
settings: !data.settings
|
|
341
|
+
? state.settings
|
|
342
|
+
: {
|
|
343
|
+
...DEFAULT_APP_CONTEXT.settings,
|
|
344
|
+
...data.settings,
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
return state;
|
|
349
|
+
}
|
|
350
|
+
case 'APP_SWITCH_PRIMARY_ORGANIZATION': {
|
|
351
|
+
return {
|
|
352
|
+
...state,
|
|
353
|
+
primaryOrganizationId: data.primaryOrganizationId,
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
case 'APP_THEME': {
|
|
357
|
+
if (!data?.preview) {
|
|
358
|
+
// Active theme
|
|
359
|
+
return {
|
|
360
|
+
...state,
|
|
361
|
+
previewTheme: null,
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// Is preview theme
|
|
366
|
+
return {
|
|
367
|
+
...state,
|
|
368
|
+
previewTheme: data.theme,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
case 'APP_LIGHT_MODE': {
|
|
372
|
+
if (!data.lightMode && !data.preview) {
|
|
373
|
+
console.warn(
|
|
374
|
+
'Developer error in setLightMode(): You cannot set active lightMode to null.',
|
|
375
|
+
);
|
|
376
|
+
return state;
|
|
377
|
+
} else if (data.preview) {
|
|
378
|
+
return {
|
|
379
|
+
...state,
|
|
380
|
+
previewLightMode: data.lightMode,
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return {
|
|
385
|
+
...state,
|
|
386
|
+
previewLightMode: null,
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
case 'APP_SYSTEM_LIGHT_MODE': {
|
|
390
|
+
return {
|
|
391
|
+
...state,
|
|
392
|
+
systemLightMode: data.lightMode,
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
default:
|
|
396
|
+
console.dev('Unknown app reducer action type:', __type);
|
|
397
|
+
return state;
|
|
398
|
+
}
|
|
362
399
|
};
|
|
363
400
|
|
|
364
401
|
export const AppContext = createContext({
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
402
|
+
appState: DEFAULT_APP_CONTEXT as AppContextData,
|
|
403
|
+
dispatchApp: (() => {
|
|
404
|
+
console.warn('AppContext has been re-initialized due to hot refresh.');
|
|
405
|
+
}) as AppContextDispatch,
|
|
369
406
|
});
|
|
370
407
|
|
|
371
408
|
/**
|
|
@@ -373,30 +410,44 @@ export const AppContext = createContext({
|
|
|
373
410
|
*/
|
|
374
411
|
|
|
375
412
|
export function useCurrentAccount() {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
413
|
+
const {
|
|
414
|
+
appState: {
|
|
415
|
+
activated,
|
|
416
|
+
hasPassword,
|
|
417
|
+
webVersion,
|
|
418
|
+
alertUpdatesOnMount,
|
|
419
|
+
account,
|
|
420
|
+
settings,
|
|
421
|
+
primaryOrganizationId,
|
|
422
|
+
},
|
|
423
|
+
dispatchApp,
|
|
424
|
+
} = useContext(AppContext);
|
|
425
|
+
const hasName = !!account?.profile?.firstName || !!account?.profile?.lastName;
|
|
426
|
+
const { fullName, displayName } = getDisplayName(
|
|
427
|
+
account?.profile?.firstName,
|
|
428
|
+
account?.profile?.lastName,
|
|
429
|
+
);
|
|
430
|
+
|
|
431
|
+
return {
|
|
432
|
+
// Dispatch
|
|
433
|
+
dispatchApp,
|
|
434
|
+
|
|
435
|
+
// App state
|
|
436
|
+
account,
|
|
437
|
+
settings,
|
|
438
|
+
activated,
|
|
439
|
+
hasPassword,
|
|
440
|
+
webVersion,
|
|
441
|
+
alertUpdatesOnMount,
|
|
442
|
+
|
|
443
|
+
// Computed
|
|
444
|
+
isLoggedIn: !!account?.id,
|
|
445
|
+
hasName,
|
|
446
|
+
fullName,
|
|
447
|
+
displayName,
|
|
448
|
+
labelName: displayName || account?.email?.address || '?',
|
|
449
|
+
primaryOrganizationId,
|
|
450
|
+
};
|
|
400
451
|
}
|
|
401
452
|
|
|
402
453
|
/**
|
|
@@ -404,6 +455,8 @@ export function useCurrentAccount() {
|
|
|
404
455
|
*/
|
|
405
456
|
|
|
406
457
|
export function useIsLoggedIn() {
|
|
407
|
-
|
|
408
|
-
|
|
458
|
+
const {
|
|
459
|
+
appState: { account },
|
|
460
|
+
} = useContext(AppContext);
|
|
461
|
+
return !!account?.id;
|
|
409
462
|
}
|