Authored by 于良

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

@@ -139,6 +139,8 @@ export default class Home extends React.Component { @@ -139,6 +139,8 @@ export default class Home extends React.Component {
139 this._renderRow = this._renderRow.bind(this); 139 this._renderRow = this._renderRow.bind(this);
140 this._renderSectionHeader = this._renderSectionHeader.bind(this); 140 this._renderSectionHeader = this._renderSectionHeader.bind(this);
141 this._renderSeparator = this._renderSeparator.bind(this); 141 this._renderSeparator = this._renderSeparator.bind(this);
  142 + this.triggerPullToRefresh = this.triggerPullToRefresh.bind(this);
  143 +
142 this.dataSource = new ListView.DataSource({ 144 this.dataSource = new ListView.DataSource({
143 rowHasChanged: (r1, r2) => !Immutable.is(r1, r2), 145 rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
144 sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2), 146 sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2),
@@ -146,6 +148,10 @@ export default class Home extends React.Component { @@ -146,6 +148,10 @@ export default class Home extends React.Component {
146 } 148 }
147 149
148 componentDidMount() { 150 componentDidMount() {
  151 + this.triggerPullToRefresh();
  152 + }
  153 +
  154 + triggerPullToRefresh() {
149 InteractionManager.runAfterInteractions(() => { 155 InteractionManager.runAfterInteractions(() => {
150 this.listView && this.listView.getScrollResponder().startPullToRefresh(); 156 this.listView && this.listView.getScrollResponder().startPullToRefresh();
151 }); 157 });
@@ -12,6 +12,8 @@ export default keyMirror({ @@ -12,6 +12,8 @@ export default keyMirror({
12 SYNC_USER_SUCCESS: null, 12 SYNC_USER_SUCCESS: null,
13 SYNC_USER_FAILURE: null, 13 SYNC_USER_FAILURE: null,
14 14
  15 + USER_DID_LOGOUT: null,
  16 +
15 GO_TO_USER: null, 17 GO_TO_USER: null,
16 GO_TO_SECTION: null, 18 GO_TO_SECTION: null,
17 GO_TO_USER_THAT_NOT_ME: null, 19 GO_TO_USER_THAT_NOT_ME: null,
@@ -86,6 +86,8 @@ class HomeContainer extends React.Component { @@ -86,6 +86,8 @@ class HomeContainer extends React.Component {
86 this._onUploadSuccess = this._onUploadSuccess.bind(this); 86 this._onUploadSuccess = this._onUploadSuccess.bind(this);
87 this._onSaveingTheWorld = this._onSaveingTheWorld.bind(this); 87 this._onSaveingTheWorld = this._onSaveingTheWorld.bind(this);
88 88
  89 + this.triggerPullToRefresh = this.triggerPullToRefresh.bind(this);
  90 +
89 if (parseInt(this.props.app.container) === 1) { 91 if (parseInt(this.props.app.container) === 1) {
90 this.subscription = NativeAppEventEmitter.addListener( 92 this.subscription = NativeAppEventEmitter.addListener(
91 'ChannelReminder', 93 'ChannelReminder',
@@ -95,6 +97,24 @@ class HomeContainer extends React.Component { @@ -95,6 +97,24 @@ class HomeContainer extends React.Component {
95 } 97 }
96 ); 98 );
97 } 99 }
  100 +
  101 + this.subscription2 = NativeAppEventEmitter.addListener(
  102 + 'UserDidLoginReminder',
  103 + (reminder) => {
  104 + let uid = reminder.uid;
  105 + this.props.actions.setUid(uid);
  106 + this.props.actions.syncUserWithSSOUid(uid);
  107 + this.triggerPullToRefresh();
  108 + }
  109 + );
  110 +
  111 + this.subscription3 = NativeAppEventEmitter.addListener(
  112 + 'UserDidLogoutReminder',
  113 + (reminder) => {
  114 + this.props.actions.userDidLogout();
  115 + this.triggerPullToRefresh();
  116 + }
  117 + );
98 } 118 }
99 119
100 componentDidMount() { 120 componentDidMount() {
@@ -114,6 +134,13 @@ class HomeContainer extends React.Component { @@ -114,6 +134,13 @@ class HomeContainer extends React.Component {
114 if (parseInt(this.props.app.container) === 1) { 134 if (parseInt(this.props.app.container) === 1) {
115 this.subscription && this.subscription.remove(); 135 this.subscription && this.subscription.remove();
116 } 136 }
  137 +
  138 + this.subscription2 && this.subscription2.remove();
  139 + this.subscription3 && this.subscription3.remove();
  140 + }
  141 +
  142 + triggerPullToRefresh() {
  143 + this.home && this.home.triggerPullToRefresh();
117 } 144 }
118 145
119 _onPressBanner(url) { 146 _onPressBanner(url) {
@@ -121,7 +148,6 @@ class HomeContainer extends React.Component { @@ -121,7 +148,6 @@ class HomeContainer extends React.Component {
121 } 148 }
122 149
123 _onPressNotice(url) { 150 _onPressNotice(url) {
124 - // 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"}}`;  
125 this.props.actions.goAction(url); 151 this.props.actions.goAction(url);
126 } 152 }
127 153
@@ -178,7 +204,6 @@ class HomeContainer extends React.Component { @@ -178,7 +204,6 @@ class HomeContainer extends React.Component {
178 } 204 }
179 205
180 _onSaveingTheWorld() { 206 _onSaveingTheWorld() {
181 - console.log('onSaveingTheWorld');  
182 this.props.actions.goToUser({},this.props.navigationState.name); 207 this.props.actions.goToUser({},this.props.navigationState.name);
183 } 208 }
184 209
@@ -219,6 +244,9 @@ class HomeContainer extends React.Component { @@ -219,6 +244,9 @@ class HomeContainer extends React.Component {
219 return ( 244 return (
220 <View style={[styles.container, containerStyle]}> 245 <View style={[styles.container, containerStyle]}>
221 <Home 246 <Home
  247 + ref={(c) => {
  248 + this.home = c;
  249 + }}
222 progressing={progressing} 250 progressing={progressing}
223 banner={bannerData} 251 banner={bannerData}
224 bannerDuration={banner.duration} 252 bannerDuration={banner.duration}
@@ -57,8 +57,16 @@ const { @@ -57,8 +57,16 @@ const {
57 SETTING_MODI_NICKNAME, 57 SETTING_MODI_NICKNAME,
58 SETTING_MODI_SIGNATURE, 58 SETTING_MODI_SIGNATURE,
59 59
  60 + USER_DID_LOGOUT,
  61 +
60 } = require('../../constants/actionTypes').default; 62 } = require('../../constants/actionTypes').default;
61 63
  64 +export function userDidLogout() {
  65 + return {
  66 + type: USER_DID_LOGOUT,
  67 + };
  68 +}
  69 +
62 export function postRequest(ptr) { 70 export function postRequest(ptr) {
63 return { 71 return {
64 type: USER_POSTS_REQUEST, 72 type: USER_POSTS_REQUEST,
@@ -52,6 +52,8 @@ const { @@ -52,6 +52,8 @@ const {
52 SETTING_MODI_NICKNAME, 52 SETTING_MODI_NICKNAME,
53 SETTING_MODI_SIGNATURE, 53 SETTING_MODI_SIGNATURE,
54 54
  55 + USER_DID_LOGOUT,
  56 +
55 } = require('../../constants/actionTypes').default; 57 } = require('../../constants/actionTypes').default;
56 58
57 const initialState = new InitialState; 59 const initialState = new InitialState;
@@ -62,11 +64,6 @@ export default function user(state = initialState, action) { @@ -62,11 +64,6 @@ export default function user(state = initialState, action) {
62 } 64 }
63 65
64 switch (action.type) { 66 switch (action.type) {
65 - case USER_BACKGROUND_TAP:  
66 - {  
67 - // let nextState = state.set  
68 - }  
69 - break;  
70 67
71 case USER_POSTS_REQUEST: { 68 case USER_POSTS_REQUEST: {
72 let nextState = state.setIn(['posts', 'isFetching'], true) 69 let nextState = state.setIn(['posts', 'isFetching'], true)
@@ -74,7 +71,6 @@ export default function user(state = initialState, action) { @@ -74,7 +71,6 @@ export default function user(state = initialState, action) {
74 .set('ptr', action.payload); 71 .set('ptr', action.payload);
75 return nextState; 72 return nextState;
76 } 73 }
77 - break;  
78 74
79 case USER_LIKE_REQUEST: { 75 case USER_LIKE_REQUEST: {
80 let nextState = state.setIn(['like', 'isFetching'], true) 76 let nextState = state.setIn(['like', 'isFetching'], true)
@@ -82,7 +78,6 @@ export default function user(state = initialState, action) { @@ -82,7 +78,6 @@ export default function user(state = initialState, action) {
82 .set('ptr', action.payload); 78 .set('ptr', action.payload);
83 return nextState; 79 return nextState;
84 } 80 }
85 - break;  
86 81
87 case USER_REPLY_REQUEST: { 82 case USER_REPLY_REQUEST: {
88 let nextState = state.setIn(['reply', 'isFetching'], true) 83 let nextState = state.setIn(['reply', 'isFetching'], true)
@@ -90,10 +85,8 @@ export default function user(state = initialState, action) { @@ -90,10 +85,8 @@ export default function user(state = initialState, action) {
90 .set('ptr', action.payload); 85 .set('ptr', action.payload);
91 return nextState; 86 return nextState;
92 } 87 }
93 - break;  
94 88
95 - case USER_POSTS_SUCCESS:  
96 - { 89 + case USER_POSTS_SUCCESS: {
97 // let nextState = state.set 90 // let nextState = state.set
98 let {lastedTime, list, endReached} = action.payload; 91 let {lastedTime, list, endReached} = action.payload;
99 92
@@ -106,10 +99,8 @@ export default function user(state = initialState, action) { @@ -106,10 +99,8 @@ export default function user(state = initialState, action) {
106 99
107 return nextState; 100 return nextState;
108 } 101 }
109 - break;  
110 102
111 - case USER_LIKE_SUCCESS:  
112 - { 103 + case USER_LIKE_SUCCESS: {
113 // let nextState = state.set 104 // let nextState = state.set
114 let {lastedTime, list, endReached} = action.payload; 105 let {lastedTime, list, endReached} = action.payload;
115 106
@@ -122,10 +113,8 @@ export default function user(state = initialState, action) { @@ -122,10 +113,8 @@ export default function user(state = initialState, action) {
122 113
123 return nextState; 114 return nextState;
124 } 115 }
125 - break;  
126 116
127 - case USER_REPLY_SUCCESS:  
128 - { 117 + case USER_REPLY_SUCCESS: {
129 // let nextState = state.set 118 // let nextState = state.set
130 let {lastedTime, list, endReached} = action.payload; 119 let {lastedTime, list, endReached} = action.payload;
131 120
@@ -138,7 +127,6 @@ export default function user(state = initialState, action) { @@ -138,7 +127,6 @@ export default function user(state = initialState, action) {
138 127
139 return nextState; 128 return nextState;
140 } 129 }
141 - break;  
142 130
143 case USER_POSTS_FAILURE: { 131 case USER_POSTS_FAILURE: {
144 let nextState = state.setIn(['posts', 'isFetching'], false) 132 let nextState = state.setIn(['posts', 'isFetching'], false)
@@ -146,7 +134,6 @@ export default function user(state = initialState, action) { @@ -146,7 +134,6 @@ export default function user(state = initialState, action) {
146 .set('ptr', false); 134 .set('ptr', false);
147 return nextState; 135 return nextState;
148 } 136 }
149 - break;  
150 137
151 case USER_LIKE_FAILURE: { 138 case USER_LIKE_FAILURE: {
152 let nextState = state.setIn(['like', 'isFetching'], false) 139 let nextState = state.setIn(['like', 'isFetching'], false)
@@ -154,7 +141,6 @@ export default function user(state = initialState, action) { @@ -154,7 +141,6 @@ export default function user(state = initialState, action) {
154 .set('ptr', false); 141 .set('ptr', false);
155 return nextState; 142 return nextState;
156 } 143 }
157 - break;  
158 144
159 case USER_REPLY_FAILURE: { 145 case USER_REPLY_FAILURE: {
160 let nextState = state.setIn(['reply', 'isFetching'], false) 146 let nextState = state.setIn(['reply', 'isFetching'], false)
@@ -162,18 +148,15 @@ export default function user(state = initialState, action) { @@ -162,18 +148,15 @@ export default function user(state = initialState, action) {
162 .set('ptr', false); 148 .set('ptr', false);
163 return nextState; 149 return nextState;
164 } 150 }
165 - break;  
166 151
167 case USER_GO_TO_SETTING_STATS: 152 case USER_GO_TO_SETTING_STATS:
168 return state; 153 return state;
169 - break;  
170 154
171 case SYNC_USER_REQUEST: { 155 case SYNC_USER_REQUEST: {
172 let nextState = state.setIn(['profile', 'isFetching'], true) 156 let nextState = state.setIn(['profile', 'isFetching'], true)
173 .setIn(['profile', 'error'], null); 157 .setIn(['profile', 'error'], null);
174 return nextState; 158 return nextState;
175 } 159 }
176 - break;  
177 160
178 case SYNC_USER_SUCCESS: { 161 case SYNC_USER_SUCCESS: {
179 let {avatar, backgroundImage, nickName, realName, gender, sign, age, birthday, height, weight, msgCount} = action.payload; 162 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) { @@ -194,74 +177,60 @@ export default function user(state = initialState, action) {
194 .setIn(['setting', 'signature'], sign); 177 .setIn(['setting', 'signature'], sign);
195 return nextState; 178 return nextState;
196 } 179 }
197 - break;  
198 180
199 case SYNC_USER_FAILURE: { 181 case SYNC_USER_FAILURE: {
200 let nextState = state.setIn(['profile', 'isFetching'], false) 182 let nextState = state.setIn(['profile', 'isFetching'], false)
201 .setIn(['profile', 'error'], action.payload); 183 .setIn(['profile', 'error'], action.payload);
202 return nextState; 184 return nextState;
203 } 185 }
204 - break;  
205 186
206 case SET_UID: 187 case SET_UID:
207 return state.setIn(['profile', 'uid'], action.payload); 188 return state.setIn(['profile', 'uid'], action.payload);
208 - break;  
209 189
210 case USER_SET_ACTIVE_TAB: 190 case USER_SET_ACTIVE_TAB:
211 return state.set('activeTab', action.payload); 191 return state.set('activeTab', action.payload);
212 - break;  
213 192
214 - case USER_CLEAN:  
215 - { 193 + case USER_CLEAN: {
216 let nextState = initialState.set('profile', state.profile); 194 let nextState = initialState.set('profile', state.profile);
217 return nextState; 195 return nextState;
218 } 196 }
219 - break;  
220 197
221 case USER_UNREAD_SUCCESS: 198 case USER_UNREAD_SUCCESS:
222 return state.setIn(['profile', 'msgCount'], action.payload); 199 return state.setIn(['profile', 'msgCount'], action.payload);
223 - break;  
224 200
225 case USER_UNREAD_FAILURE: 201 case USER_UNREAD_FAILURE:
226 return state.setIn(['profile','error'], action.payload); 202 return state.setIn(['profile','error'], action.payload);
227 - break;  
228 203
229 case USER_AVATAR_UPLOADING:{ 204 case USER_AVATAR_UPLOADING:{
230 - let nextState = state.set('avatarUploading',true).set('avatarUploadError',null); 205 + let nextState = state.set('avatarUploading',true).set('avatarUploadError', null);
231 return nextState; 206 return nextState;
232 } 207 }
233 - break; 208 +
234 case USER_AVATAR_UPLOAD_SUCCESS:{ 209 case USER_AVATAR_UPLOAD_SUCCESS:{
235 - let nextState = state.set('avatarUploading',false).set('avatarUploadError',null); 210 + let nextState = state.set('avatarUploading', false).set('avatarUploadError', null);
236 return nextState; 211 return nextState;
237 } 212 }
238 213
239 - break;  
240 case USER_AVATAR_UPLOAD_FAILURE: { 214 case USER_AVATAR_UPLOAD_FAILURE: {
241 - let nextState = state.set('avatarUploading',false).set('avatarUploadError',action.payload); 215 + let nextState = state.set('avatarUploading', false).set('avatarUploadError', action.payload);
242 return nextState; 216 return nextState;
243 } 217 }
244 218
245 - break;  
246 case USER_BG_UPLOADING: { 219 case USER_BG_UPLOADING: {
247 - let nextState = state.set('bgUploading',true).set('bgUploadError',null); 220 + let nextState = state.set('bgUploading', true).set('bgUploadError', null);
248 return nextState; 221 return nextState;
249 } 222 }
250 223
251 - break;  
252 case USER_BG_UPLOAD_SUCCESS: { 224 case USER_BG_UPLOAD_SUCCESS: {
253 - let nextState = state.set('bgUploading',false).set('bgUploadError',null); 225 + let nextState = state.set('bgUploading', false).set('bgUploadError', null);
254 return nextState; 226 return nextState;
255 } 227 }
256 228
257 - break;  
258 case USER_BG_UPLOAD_FAILURE: { 229 case USER_BG_UPLOAD_FAILURE: {
259 - let nextState = state.set('bgUploading',false).set('bgUploadError',action.payload); 230 + let nextState = state.set('bgUploading', false).set('bgUploadError', action.payload);
260 return nextState; 231 return nextState;
261 } 232 }
262 233
263 - break;  
264 -  
265 case POST_LIKE_REQUEST: { 234 case POST_LIKE_REQUEST: {
266 return userCenterNewLikeState(state, action.payload, true); 235 return userCenterNewLikeState(state, action.payload, true);
267 } 236 }
@@ -274,36 +243,25 @@ export default function user(state = initialState, action) { @@ -274,36 +243,25 @@ export default function user(state = initialState, action) {
274 return state.setIn(['setting', 'error'], null) 243 return state.setIn(['setting', 'error'], null)
275 .setIn(['setting','success'], false); 244 .setIn(['setting','success'], false);
276 245
277 - break;  
278 -  
279 - case SETTING_SAVE_SUCCESS:  
280 - {  
281 - console.log('state.setting.nickName ==== '+state.setting.nickName);  
282 - console.log('state.setting.signature ==== '+state.setting.signature); 246 + case SETTING_SAVE_SUCCESS: {
283 return state.setIn(['setting', 'error'], null) 247 return state.setIn(['setting', 'error'], null)
284 - .setIn(['profile','nickName'], state.setting.nickName)  
285 - .setIn(['profile','sign'], state.setting.signature)  
286 - .setIn(['setting','success'], true); 248 + .setIn(['profile','nickName'], state.setting.nickName)
  249 + .setIn(['profile','sign'], state.setting.signature)
  250 + .setIn(['setting','success'], true);
287 } 251 }
288 252
289 - break;  
290 -  
291 case SETTING_SAVE_FAILURE: 253 case SETTING_SAVE_FAILURE:
292 return state.setIn(['setting', 'error'], action.payload) 254 return state.setIn(['setting', 'error'], action.payload)
293 - .setIn(['setting','success'], false);  
294 -  
295 - break; 255 + .setIn(['setting','success'], false);
296 256
297 case SETTING_MODI_NICKNAME: 257 case SETTING_MODI_NICKNAME:
298 - console.log('set nike name ====' + action.payload);  
299 return state.setIn(['setting', 'nickName'], action.payload); 258 return state.setIn(['setting', 'nickName'], action.payload);
300 259
301 - break;  
302 -  
303 case SETTING_MODI_SIGNATURE: 260 case SETTING_MODI_SIGNATURE:
304 return state.setIn(['setting', 'signature'], action.payload); 261 return state.setIn(['setting', 'signature'], action.payload);
305 262
306 - break; 263 + case USER_DID_LOGOUT:
  264 + return initialState;
307 265
308 } 266 }
309 267