Authored by 于良

增加登录和退出登录的事件监听 review by 盖剑秋

... ... @@ -139,6 +139,8 @@ export default class Home extends React.Component {
this._renderRow = this._renderRow.bind(this);
this._renderSectionHeader = this._renderSectionHeader.bind(this);
this._renderSeparator = this._renderSeparator.bind(this);
this.triggerPullToRefresh = this.triggerPullToRefresh.bind(this);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2),
... ... @@ -146,6 +148,10 @@ export default class Home extends React.Component {
}
componentDidMount() {
this.triggerPullToRefresh();
}
triggerPullToRefresh() {
InteractionManager.runAfterInteractions(() => {
this.listView && this.listView.getScrollResponder().startPullToRefresh();
});
... ...
... ... @@ -12,6 +12,8 @@ export default keyMirror({
SYNC_USER_SUCCESS: null,
SYNC_USER_FAILURE: null,
USER_DID_LOGOUT: null,
GO_TO_USER: null,
GO_TO_SECTION: null,
GO_TO_USER_THAT_NOT_ME: null,
... ...
... ... @@ -86,6 +86,8 @@ class HomeContainer extends React.Component {
this._onUploadSuccess = this._onUploadSuccess.bind(this);
this._onSaveingTheWorld = this._onSaveingTheWorld.bind(this);
this.triggerPullToRefresh = this.triggerPullToRefresh.bind(this);
if (parseInt(this.props.app.container) === 1) {
this.subscription = NativeAppEventEmitter.addListener(
'ChannelReminder',
... ... @@ -95,6 +97,24 @@ class HomeContainer extends React.Component {
}
);
}
this.subscription2 = NativeAppEventEmitter.addListener(
'UserDidLoginReminder',
(reminder) => {
let uid = reminder.uid;
this.props.actions.setUid(uid);
this.props.actions.syncUserWithSSOUid(uid);
this.triggerPullToRefresh();
}
);
this.subscription3 = NativeAppEventEmitter.addListener(
'UserDidLogoutReminder',
(reminder) => {
this.props.actions.userDidLogout();
this.triggerPullToRefresh();
}
);
}
componentDidMount() {
... ... @@ -114,6 +134,13 @@ class HomeContainer extends React.Component {
if (parseInt(this.props.app.container) === 1) {
this.subscription && this.subscription.remove();
}
this.subscription2 && this.subscription2.remove();
this.subscription3 && this.subscription3.remove();
}
triggerPullToRefresh() {
this.home && this.home.triggerPullToRefresh();
}
_onPressBanner(url) {
... ... @@ -121,7 +148,6 @@ class HomeContainer extends React.Component {
}
_onPressNotice(url) {
// url = `http://feature.yoho.cn/0714/0714ITEMBOY/index.html?title=男生分会场&share_id=814&openby:yohobuy={"action":"go.comm.h5","params":{"product_skn":51285070,"forumid":10003,"param":{"share_id":"814","title":"男生分会场"},"share":"/operations/api/v5/webshare/getShare","shareparam":{"share_id":"814"},"title":"男生分会场","url":"http://feature.yoho.cn/0714/0714ITEMBOY/index.html"}}`;
this.props.actions.goAction(url);
}
... ... @@ -178,7 +204,6 @@ class HomeContainer extends React.Component {
}
_onSaveingTheWorld() {
console.log('onSaveingTheWorld');
this.props.actions.goToUser({},this.props.navigationState.name);
}
... ... @@ -219,6 +244,9 @@ class HomeContainer extends React.Component {
return (
<View style={[styles.container, containerStyle]}>
<Home
ref={(c) => {
this.home = c;
}}
progressing={progressing}
banner={bannerData}
bannerDuration={banner.duration}
... ...
... ... @@ -57,8 +57,16 @@ const {
SETTING_MODI_NICKNAME,
SETTING_MODI_SIGNATURE,
USER_DID_LOGOUT,
} = require('../../constants/actionTypes').default;
export function userDidLogout() {
return {
type: USER_DID_LOGOUT,
};
}
export function postRequest(ptr) {
return {
type: USER_POSTS_REQUEST,
... ...
... ... @@ -52,6 +52,8 @@ const {
SETTING_MODI_NICKNAME,
SETTING_MODI_SIGNATURE,
USER_DID_LOGOUT,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
... ... @@ -62,11 +64,6 @@ export default function user(state = initialState, action) {
}
switch (action.type) {
case USER_BACKGROUND_TAP:
{
// let nextState = state.set
}
break;
case USER_POSTS_REQUEST: {
let nextState = state.setIn(['posts', 'isFetching'], true)
... ... @@ -74,7 +71,6 @@ export default function user(state = initialState, action) {
.set('ptr', action.payload);
return nextState;
}
break;
case USER_LIKE_REQUEST: {
let nextState = state.setIn(['like', 'isFetching'], true)
... ... @@ -82,7 +78,6 @@ export default function user(state = initialState, action) {
.set('ptr', action.payload);
return nextState;
}
break;
case USER_REPLY_REQUEST: {
let nextState = state.setIn(['reply', 'isFetching'], true)
... ... @@ -90,10 +85,8 @@ export default function user(state = initialState, action) {
.set('ptr', action.payload);
return nextState;
}
break;
case USER_POSTS_SUCCESS:
{
case USER_POSTS_SUCCESS: {
// let nextState = state.set
let {lastedTime, list, endReached} = action.payload;
... ... @@ -106,10 +99,8 @@ export default function user(state = initialState, action) {
return nextState;
}
break;
case USER_LIKE_SUCCESS:
{
case USER_LIKE_SUCCESS: {
// let nextState = state.set
let {lastedTime, list, endReached} = action.payload;
... ... @@ -122,10 +113,8 @@ export default function user(state = initialState, action) {
return nextState;
}
break;
case USER_REPLY_SUCCESS:
{
case USER_REPLY_SUCCESS: {
// let nextState = state.set
let {lastedTime, list, endReached} = action.payload;
... ... @@ -138,7 +127,6 @@ export default function user(state = initialState, action) {
return nextState;
}
break;
case USER_POSTS_FAILURE: {
let nextState = state.setIn(['posts', 'isFetching'], false)
... ... @@ -146,7 +134,6 @@ export default function user(state = initialState, action) {
.set('ptr', false);
return nextState;
}
break;
case USER_LIKE_FAILURE: {
let nextState = state.setIn(['like', 'isFetching'], false)
... ... @@ -154,7 +141,6 @@ export default function user(state = initialState, action) {
.set('ptr', false);
return nextState;
}
break;
case USER_REPLY_FAILURE: {
let nextState = state.setIn(['reply', 'isFetching'], false)
... ... @@ -162,18 +148,15 @@ export default function user(state = initialState, action) {
.set('ptr', false);
return nextState;
}
break;
case USER_GO_TO_SETTING_STATS:
return state;
break;
case SYNC_USER_REQUEST: {
let nextState = state.setIn(['profile', 'isFetching'], true)
.setIn(['profile', 'error'], null);
return nextState;
}
break;
case SYNC_USER_SUCCESS: {
let {avatar, backgroundImage, nickName, realName, gender, sign, age, birthday, height, weight, msgCount} = action.payload;
... ... @@ -194,74 +177,60 @@ export default function user(state = initialState, action) {
.setIn(['setting', 'signature'], sign);
return nextState;
}
break;
case SYNC_USER_FAILURE: {
let nextState = state.setIn(['profile', 'isFetching'], false)
.setIn(['profile', 'error'], action.payload);
return nextState;
}
break;
case SET_UID:
return state.setIn(['profile', 'uid'], action.payload);
break;
case USER_SET_ACTIVE_TAB:
return state.set('activeTab', action.payload);
break;
case USER_CLEAN:
{
case USER_CLEAN: {
let nextState = initialState.set('profile', state.profile);
return nextState;
}
break;
case USER_UNREAD_SUCCESS:
return state.setIn(['profile', 'msgCount'], action.payload);
break;
case USER_UNREAD_FAILURE:
return state.setIn(['profile','error'], action.payload);
break;
case USER_AVATAR_UPLOADING:{
let nextState = state.set('avatarUploading',true).set('avatarUploadError',null);
let nextState = state.set('avatarUploading',true).set('avatarUploadError', null);
return nextState;
}
break;
case USER_AVATAR_UPLOAD_SUCCESS:{
let nextState = state.set('avatarUploading',false).set('avatarUploadError',null);
let nextState = state.set('avatarUploading', false).set('avatarUploadError', null);
return nextState;
}
break;
case USER_AVATAR_UPLOAD_FAILURE: {
let nextState = state.set('avatarUploading',false).set('avatarUploadError',action.payload);
let nextState = state.set('avatarUploading', false).set('avatarUploadError', action.payload);
return nextState;
}
break;
case USER_BG_UPLOADING: {
let nextState = state.set('bgUploading',true).set('bgUploadError',null);
let nextState = state.set('bgUploading', true).set('bgUploadError', null);
return nextState;
}
break;
case USER_BG_UPLOAD_SUCCESS: {
let nextState = state.set('bgUploading',false).set('bgUploadError',null);
let nextState = state.set('bgUploading', false).set('bgUploadError', null);
return nextState;
}
break;
case USER_BG_UPLOAD_FAILURE: {
let nextState = state.set('bgUploading',false).set('bgUploadError',action.payload);
let nextState = state.set('bgUploading', false).set('bgUploadError', action.payload);
return nextState;
}
break;
case POST_LIKE_REQUEST: {
return userCenterNewLikeState(state, action.payload, true);
}
... ... @@ -274,36 +243,25 @@ export default function user(state = initialState, action) {
return state.setIn(['setting', 'error'], null)
.setIn(['setting','success'], false);
break;
case SETTING_SAVE_SUCCESS:
{
console.log('state.setting.nickName ==== '+state.setting.nickName);
console.log('state.setting.signature ==== '+state.setting.signature);
case SETTING_SAVE_SUCCESS: {
return state.setIn(['setting', 'error'], null)
.setIn(['profile','nickName'], state.setting.nickName)
.setIn(['profile','sign'], state.setting.signature)
.setIn(['setting','success'], true);
}
break;
case SETTING_SAVE_FAILURE:
return state.setIn(['setting', 'error'], action.payload)
.setIn(['setting','success'], false);
break;
case SETTING_MODI_NICKNAME:
console.log('set nike name ====' + action.payload);
return state.setIn(['setting', 'nickName'], action.payload);
break;
case SETTING_MODI_SIGNATURE:
return state.setIn(['setting', 'signature'], action.payload);
break;
case USER_DID_LOGOUT:
return initialState;
}
... ...