Skip to content

Commit 0618dd4

Browse files
author
soliury
committed
add mothond logout
1 parent 49ef3fb commit 0618dd4

8 files changed

Lines changed: 28 additions & 13 deletions

File tree

src/actions/user.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { createAction } from 'redux-actions';
1+
import {createAction} from 'redux-actions';
22
import * as types from '../constants/ActionTypes';
33
import * as userService from '../services/userService';
44
import * as tokenService from '../services/token';
55
import * as storageService from '../services/storage';
66

77

8-
export const checkToken = createAction(types.CHECK_TOKEN, async (token)=> {
8+
export const checkToken = createAction(types.CHECK_TOKEN, async(token)=> {
99
const userLoginInfo = await userService.req.checkToken(token);
1010
const user = await userService.req
1111
.getUserInfo(userLoginInfo.loginname)
@@ -24,7 +24,7 @@ export const checkToken = createAction(types.CHECK_TOKEN, async (token)=> {
2424
});
2525

2626

27-
export const getUserFromStorage = createAction(types.GET_USER_FROM_STORAGE, async ()=> {
27+
export const getUserFromStorage = createAction(types.GET_USER_FROM_STORAGE, async()=> {
2828
return await userService.storage.getUser()
2929
.then(user=> {
3030
tokenService.setToken(user.secret.token);
@@ -37,7 +37,7 @@ export const getUserFromStorage = createAction(types.GET_USER_FROM_STORAGE, asyn
3737
});
3838

3939

40-
export const updateClientUserInfo = createAction(types.UPDATE_CLIENT_USER_INFO, async (user)=> {
40+
export const updateClientUserInfo = createAction(types.UPDATE_CLIENT_USER_INFO, async(user)=> {
4141
return await userService.req.getUserInfo(user.secret.loginname)
4242
.then(userInfo=> {
4343
if (userInfo) {
@@ -52,7 +52,7 @@ export const updateClientUserInfo = createAction(types.UPDATE_CLIENT_USER_INFO,
5252
});
5353

5454

55-
export const getUserInfo = createAction(types.GET_USER_INFO, async (loginName)=> {
55+
export const getUserInfo = createAction(types.GET_USER_INFO, async(loginName)=> {
5656
return await userService.req.getUserInfo(loginName)
5757
.then(userInfo=> {
5858
if (userInfo) {
@@ -67,4 +67,9 @@ export const getUserInfo = createAction(types.GET_USER_INFO, async (loginName)=>
6767
});
6868

6969

70-
export const logout = createAction(types.LOGOUT, userService.storage.clearUser);
70+
export const logout = function () {
71+
userService.storage.clearUser();
72+
return {
73+
type: types.LOGOUT
74+
}
75+
};

src/components/Setting.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class Setting extends Component {
4040

4141

4242
onLogoutPress() {
43+
this.props.router.pop();
4344
this.props.actions.logout();
44-
this.props.router.replaceWithHome()
4545
}
4646

4747

src/configs/Router.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React,{
1+
import React, {
22
Navigator
33
} from 'react-native';
44
import _ from 'lodash';
@@ -9,10 +9,13 @@ import * as User from '../layouts/User';
99
import * as Message from '../layouts/Message';
1010
import * as Topic from '../layouts/Topic';
1111
import * as Comment from '../layouts/Comment';
12+
import * as HomeComponent from '../layouts/Home';
1213
import * as CustomSceneConfigs from '../configs/sceneConfig';
1314
import connectComponent from '../utils/connectComponent';
1415

15-
const { SceneConfigs } = Navigator;
16+
17+
const Home = connectComponent(HomeComponent);
18+
const {SceneConfigs} = Navigator;
1619

1720
class Router {
1821
constructor(navigator) {

src/layouts/User.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class User extends Component {
7474

7575

7676
render() {
77-
const { userInfo={}, ui } = this.props;
77+
const { userInfo, ui } = this.props;
7878
const spinnerView = (
7979
<Spinner
8080
size="large"
@@ -255,8 +255,8 @@ const styles = StyleSheet.create({
255255
export const LayoutComponent = User;
256256
export function mapStateToProps(state, props) {
257257
const { userName } = props;
258-
let userInfo = state.user.publicInfo || {};
259-
const isClientUser = userInfo.loginname === userName;
258+
let userInfo = state.user.publicInfo || null;
259+
const isClientUser = userInfo && userInfo.loginname === userName;
260260
return {
261261
user: state.user,
262262
ui: state.userUI,

src/reducers/message.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export default function (state = initialState, action) {
3737
hasRead: state.hasNotRead.concat(state.hasRead),
3838
unreadMessageCount: 0
3939
};
40-
40+
case types.LOGOUT:
41+
return initialState;
4142
default :
4243
return state;
4344
}

src/reducers/messageUI.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export default function (state = initialState, action) {
2727
...state,
2828
fetchUnreadMessageCountPending: sequence.type === 'start'
2929
};
30+
case types.LOGOUT:
31+
return initialState;
3032
default:
3133
return state;
3234
}

src/reducers/user.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export default function (state = initialState, action) {
4242
[userName]: payload
4343
}
4444
};
45+
case types.LOGOUT:
46+
return initialState;
4547
default:
4648
return state;
4749
}

src/reducers/userUI.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export default function (state = initialState, action) {
2727
...state,
2828
otherUserPending: sequence.type === 'start'
2929
};
30+
case types.LOGOUT:
31+
return initialState;
3032
default:
3133
return state;
3234
}

0 commit comments

Comments
 (0)