Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit 6a138f2

Browse files
author
soliury
committed
fix bugs: on launch the app have not fetch the unread message
1 parent 22523b0 commit 6a138f2

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

src/actions/utils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,9 @@ export const getReducerFromAsyncStorage = createAction(types.GET_REDUCER_FROM_AS
3030
.catch(err=> {
3131
console.warn(err);
3232
});
33+
}, (resolved, rejected)=> {
34+
return {
35+
resolved,
36+
rejected
37+
}
3338
});

src/layouts/Utils.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React, {
44
StyleSheet,
55
Text,
66
StatusBar,
7+
AppState
78
} from 'react-native';
89
import Toast from '../components/base/Toast';
910
import * as codePushUtils from '../utils/codePushSync';
@@ -12,13 +13,24 @@ import * as codePushUtils from '../utils/codePushSync';
1213
class Utils extends Component {
1314
componentDidMount() {
1415
const {actions} = this.props;
15-
actions.getReducerFromAsyncStorage();
16+
actions.getReducerFromAsyncStorage(({user})=> {
17+
if (user && user.secret) {
18+
actions.getUnreadMessageCount();
19+
}
20+
});
21+
codePushUtils.sync();
22+
AppState.addEventListener("change", (newState) => {
23+
if (newState === "active") {
24+
codePushUtils.sync();
25+
this.props.user.secret && actions.getUnreadMessageCount();
26+
}
27+
});
28+
1629
// if (__DEV__) {
1730
// actions.checkToken('your secretKey', ()=> {
1831
// actions.toast('登陆成功');
1932
// });
2033
// }
21-
codePushUtils.init();
2234
}
2335

2436

@@ -51,8 +63,9 @@ const styles = StyleSheet.create({
5163

5264
export const LayoutComponent = Utils;
5365
export function mapStateToProps(state) {
54-
const {utils = {}} = state;
66+
const {utils = {}, user} = state;
5567
return {
56-
...utils
68+
...utils,
69+
user
5770
}
5871
}

src/utils/codePushSync.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ export function shouldSync() {
2121
}
2222

2323

24-
export function init() {
24+
export function sync() {
2525
shouldSync().done((shouldSync)=>shouldSync && codePush.sync());
26-
AppState.addEventListener("change", (newState) => {
27-
if (newState === "active") {
28-
shouldSync().done((shouldSync)=>shouldSync && codePush.sync());
29-
}
30-
});
3126
}

0 commit comments

Comments
 (0)