@etsoo/react 1.3.55 → 1.3.59
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/lib/app/ReactApp.d.ts +1 -0
- package/lib/app/ReactApp.js +6 -9
- package/lib/states/UserState.js +1 -0
- package/package.json +1 -1
- package/src/app/ReactApp.ts +13 -11
- package/src/states/UserState.ts +1 -0
package/lib/app/ReactApp.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { InputDialogProps } from './InputDialogProps';
|
|
|
13
13
|
* Case 1: undefined, when refresh the whole page
|
|
14
14
|
* Case 2: false, unauthorized
|
|
15
15
|
* Case 3: true, authorized or considered as authorized (maynot, like token expiry)
|
|
16
|
+
* Case 4: property or properties changed
|
|
16
17
|
* @param props Props
|
|
17
18
|
* @returns Component
|
|
18
19
|
*/
|
package/lib/app/ReactApp.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CoreApp, createClient } from '@etsoo/appscript';
|
|
2
|
-
import { Utils } from '@etsoo/shared';
|
|
3
2
|
import React from 'react';
|
|
4
3
|
import { NotifierMU } from '../mu/NotifierMU';
|
|
5
4
|
import { ProgressCount } from '../mu/ProgressCount';
|
|
@@ -14,6 +13,7 @@ let globalApp;
|
|
|
14
13
|
* Case 1: undefined, when refresh the whole page
|
|
15
14
|
* Case 2: false, unauthorized
|
|
16
15
|
* Case 3: true, authorized or considered as authorized (maynot, like token expiry)
|
|
16
|
+
* Case 4: property or properties changed
|
|
17
17
|
* @param props Props
|
|
18
18
|
* @returns Component
|
|
19
19
|
*/
|
|
@@ -25,6 +25,7 @@ export function ReactAppStateDetector(props) {
|
|
|
25
25
|
? { state: {} }
|
|
26
26
|
: React.useContext(globalApp.userState.context);
|
|
27
27
|
// Match fields
|
|
28
|
+
const authorized = state.authorized;
|
|
28
29
|
const changedFields = state.lastChangedFields;
|
|
29
30
|
let matchedFields;
|
|
30
31
|
if (targetFields == null || changedFields == null) {
|
|
@@ -37,11 +38,12 @@ export function ReactAppStateDetector(props) {
|
|
|
37
38
|
matchedFields === null || matchedFields === void 0 ? void 0 : matchedFields.push(targetField);
|
|
38
39
|
});
|
|
39
40
|
}
|
|
41
|
+
console.log('ReactAppStateDetector', changedFields, targetFields, matchedFields);
|
|
40
42
|
// Ready
|
|
41
43
|
React.useEffect(() => {
|
|
42
44
|
// Callback
|
|
43
|
-
update(
|
|
44
|
-
}, [
|
|
45
|
+
update(authorized, matchedFields);
|
|
46
|
+
}, [authorized, matchedFields]);
|
|
45
47
|
// return
|
|
46
48
|
return React.createElement(React.Fragment);
|
|
47
49
|
}
|
|
@@ -211,15 +213,10 @@ export class ReactApp extends CoreApp {
|
|
|
211
213
|
* @param keep Keep in local storage or not
|
|
212
214
|
*/
|
|
213
215
|
userLogin(user, refreshToken, keep) {
|
|
214
|
-
// Changed
|
|
215
|
-
const dataChanged = !this.authorized ||
|
|
216
|
-
this.userData == null ||
|
|
217
|
-
!Utils.objectEqual(this.userData, user, ['seconds', 'token']);
|
|
218
216
|
// Super call, set token
|
|
219
217
|
super.userLogin(user, refreshToken, keep);
|
|
220
218
|
// Dispatch action
|
|
221
|
-
|
|
222
|
-
if (this.userStateDispatch != null && dataChanged)
|
|
219
|
+
if (this.userStateDispatch != null)
|
|
223
220
|
this.userStateDispatch({
|
|
224
221
|
type: UserActionType.Login,
|
|
225
222
|
user
|
package/lib/states/UserState.js
CHANGED
package/package.json
CHANGED
package/src/app/ReactApp.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
IUserData
|
|
8
8
|
} from '@etsoo/appscript';
|
|
9
9
|
import { NotificationRenderProps } from '@etsoo/notificationbase';
|
|
10
|
-
import { DataTypes
|
|
10
|
+
import { DataTypes } from '@etsoo/shared';
|
|
11
11
|
import React from 'react';
|
|
12
12
|
import { NotifierMU } from '../mu/NotifierMU';
|
|
13
13
|
import { ProgressCount } from '../mu/ProgressCount';
|
|
@@ -37,6 +37,7 @@ let globalApp: IReactApp<IAppSettings, any, IPageData>;
|
|
|
37
37
|
* Case 1: undefined, when refresh the whole page
|
|
38
38
|
* Case 2: false, unauthorized
|
|
39
39
|
* Case 3: true, authorized or considered as authorized (maynot, like token expiry)
|
|
40
|
+
* Case 4: property or properties changed
|
|
40
41
|
* @param props Props
|
|
41
42
|
* @returns Component
|
|
42
43
|
*/
|
|
@@ -53,6 +54,7 @@ export function ReactAppStateDetector(props: IStateProps) {
|
|
|
53
54
|
);
|
|
54
55
|
|
|
55
56
|
// Match fields
|
|
57
|
+
const authorized = state.authorized;
|
|
56
58
|
const changedFields = state.lastChangedFields;
|
|
57
59
|
let matchedFields: string[] | undefined;
|
|
58
60
|
if (targetFields == null || changedFields == null) {
|
|
@@ -65,11 +67,18 @@ export function ReactAppStateDetector(props: IStateProps) {
|
|
|
65
67
|
});
|
|
66
68
|
}
|
|
67
69
|
|
|
70
|
+
console.log(
|
|
71
|
+
'ReactAppStateDetector',
|
|
72
|
+
changedFields,
|
|
73
|
+
targetFields,
|
|
74
|
+
matchedFields
|
|
75
|
+
);
|
|
76
|
+
|
|
68
77
|
// Ready
|
|
69
78
|
React.useEffect(() => {
|
|
70
79
|
// Callback
|
|
71
|
-
update(
|
|
72
|
-
}, [
|
|
80
|
+
update(authorized, matchedFields);
|
|
81
|
+
}, [authorized, matchedFields]);
|
|
73
82
|
|
|
74
83
|
// return
|
|
75
84
|
return React.createElement(React.Fragment);
|
|
@@ -356,18 +365,11 @@ export class ReactApp<
|
|
|
356
365
|
refreshToken: string,
|
|
357
366
|
keep?: boolean
|
|
358
367
|
): void {
|
|
359
|
-
// Changed
|
|
360
|
-
const dataChanged =
|
|
361
|
-
!this.authorized ||
|
|
362
|
-
this.userData == null ||
|
|
363
|
-
!Utils.objectEqual(this.userData, user, ['seconds', 'token']);
|
|
364
|
-
|
|
365
368
|
// Super call, set token
|
|
366
369
|
super.userLogin(user, refreshToken, keep);
|
|
367
370
|
|
|
368
371
|
// Dispatch action
|
|
369
|
-
|
|
370
|
-
if (this.userStateDispatch != null && dataChanged)
|
|
372
|
+
if (this.userStateDispatch != null)
|
|
371
373
|
this.userStateDispatch({
|
|
372
374
|
type: UserActionType.Login,
|
|
373
375
|
user
|