Showing
7 changed files
with
128 additions
and
61 deletions
@@ -17,7 +17,6 @@ export default class ContentListView extends Component { | @@ -17,7 +17,6 @@ export default class ContentListView extends Component { | ||
17 | constructor(props) { | 17 | constructor(props) { |
18 | super(props); | 18 | super(props); |
19 | 19 | ||
20 | - this.trigggePullToRefresh = this.trigggePullToRefresh.bind(this); | ||
21 | this._renderRow = this._renderRow.bind(this); | 20 | this._renderRow = this._renderRow.bind(this); |
22 | this._renderFooter = this._renderFooter.bind(this); | 21 | this._renderFooter = this._renderFooter.bind(this); |
23 | this.dataSource = new ListView.DataSource({ | 22 | this.dataSource = new ListView.DataSource({ |
@@ -25,19 +24,6 @@ export default class ContentListView extends Component { | @@ -25,19 +24,6 @@ export default class ContentListView extends Component { | ||
25 | }); | 24 | }); |
26 | } | 25 | } |
27 | 26 | ||
28 | - componentDidMount() { | ||
29 | - this.trigggePullToRefresh(); | ||
30 | - } | ||
31 | - | ||
32 | - trigggePullToRefresh() { | ||
33 | - if (Platform.OS === 'ios') { | ||
34 | - InteractionManager.runAfterInteractions(() => { | ||
35 | - this.listView && this.listView.getScrollResponder().startPullToRefresh(); | ||
36 | - }); | ||
37 | - } else { | ||
38 | - this.props.onRefresh && this.props.onRefresh(); | ||
39 | - } | ||
40 | - } | ||
41 | 27 | ||
42 | _renderFooter(){ | 28 | _renderFooter(){ |
43 | return ( | 29 | return ( |
@@ -17,7 +17,6 @@ export default class ContentMessageView extends Component { | @@ -17,7 +17,6 @@ export default class ContentMessageView extends Component { | ||
17 | super(props); | 17 | super(props); |
18 | 18 | ||
19 | this._renderRow = this._renderRow.bind(this); | 19 | this._renderRow = this._renderRow.bind(this); |
20 | - this.trigggePullToRefresh = this.trigggePullToRefresh.bind(this); | ||
21 | this._renderHeader = this._renderHeader.bind(this); | 20 | this._renderHeader = this._renderHeader.bind(this); |
22 | this._renderFooter = this._renderFooter.bind(this); | 21 | this._renderFooter = this._renderFooter.bind(this); |
23 | this.dataSource = new ListView.DataSource({ | 22 | this.dataSource = new ListView.DataSource({ |
@@ -25,10 +24,6 @@ export default class ContentMessageView extends Component { | @@ -25,10 +24,6 @@ export default class ContentMessageView extends Component { | ||
25 | }); | 24 | }); |
26 | } | 25 | } |
27 | 26 | ||
28 | - componentDidMount() { | ||
29 | - this.trigggePullToRefresh(); | ||
30 | - } | ||
31 | - | ||
32 | _renderRow(rowData, sectionID, rowID) { | 27 | _renderRow(rowData, sectionID, rowID) { |
33 | let showLine = this.props.commentList.length === +rowID+1 ? false : true; | 28 | let showLine = this.props.commentList.length === +rowID+1 ? false : true; |
34 | return ( | 29 | return ( |
@@ -100,16 +95,6 @@ export default class ContentMessageView extends Component { | @@ -100,16 +95,6 @@ export default class ContentMessageView extends Component { | ||
100 | ) | 95 | ) |
101 | } | 96 | } |
102 | 97 | ||
103 | - trigggePullToRefresh() { | ||
104 | - if (Platform.OS === 'ios') { | ||
105 | - InteractionManager.runAfterInteractions(() => { | ||
106 | - this.listView && this.listView.getScrollResponder().startPullToRefresh(); | ||
107 | - }); | ||
108 | - } else { | ||
109 | - this.props.onRefresh && this.props.onRefresh(); | ||
110 | - } | ||
111 | - } | ||
112 | - | ||
113 | render() { | 98 | render() { |
114 | let {commentList, isPullToRefresh, tipMessage} = this.props; | 99 | let {commentList, isPullToRefresh, tipMessage} = this.props; |
115 | 100 |
@@ -41,6 +41,10 @@ export default keyMirror({ | @@ -41,6 +41,10 @@ export default keyMirror({ | ||
41 | FETCH_CONTENT_LIST_SUCCESS: null, | 41 | FETCH_CONTENT_LIST_SUCCESS: null, |
42 | FETCH_CONTENT_LIST_FAILURE: null, | 42 | FETCH_CONTENT_LIST_FAILURE: null, |
43 | 43 | ||
44 | + FETCH_COMMENT_LIST_REQUEST: null, | ||
45 | + FETCH_COMMENT_LIST_SUCCESS: null, | ||
46 | + FETCH_COMMENT_LIST_FAILURE: null, | ||
47 | + | ||
44 | //回复评论 | 48 | //回复评论 |
45 | ADD_ARTICLE_COMMENT_REQUEST: null, | 49 | ADD_ARTICLE_COMMENT_REQUEST: null, |
46 | ADD_ARTICLE_COMMENT_SUCCESS: null, | 50 | ADD_ARTICLE_COMMENT_SUCCESS: null, |
@@ -66,7 +66,7 @@ class ContentListContainer extends Component { | @@ -66,7 +66,7 @@ class ContentListContainer extends Component { | ||
66 | } | 66 | } |
67 | 67 | ||
68 | componentDidMount() { | 68 | componentDidMount() { |
69 | - // this.props.actions.getContentList(true, this.props.contentListId) | 69 | + this.props.actions.getContentList(false, this.props.contentListId) |
70 | } | 70 | } |
71 | 71 | ||
72 | componentWillUnmount() { | 72 | componentWillUnmount() { |
@@ -21,6 +21,7 @@ const actions = [ | @@ -21,6 +21,7 @@ const actions = [ | ||
21 | 21 | ||
22 | function mapStateToProps(state) { | 22 | function mapStateToProps(state) { |
23 | return { | 23 | return { |
24 | + contentListId: state.content.contentListId, | ||
24 | tabButtons: state.content.contentType.get('list').toJS(), | 25 | tabButtons: state.content.contentType.get('list').toJS(), |
25 | commentList: state.content.commentList.get('list').toJS(), | 26 | commentList: state.content.commentList.get('list').toJS(), |
26 | isPullToRefresh: state.content.commentList.get('isPullToRefresh'), | 27 | isPullToRefresh: state.content.commentList.get('isPullToRefresh'), |
@@ -67,8 +68,8 @@ class ContentMessageContainer extends Component { | @@ -67,8 +68,8 @@ class ContentMessageContainer extends Component { | ||
67 | } | 68 | } |
68 | 69 | ||
69 | componentDidMount() { | 70 | componentDidMount() { |
70 | - // this.props.actions.getContentList(true, 4) | ||
71 | - // this.props.actions.getContentType() | 71 | + this.props.actions.getCommentList(false, this.props.contentListId) |
72 | + this.props.actions.getContentType() | ||
72 | } | 73 | } |
73 | 74 | ||
74 | componentWillUnmount() { | 75 | componentWillUnmount() { |
@@ -78,12 +79,12 @@ class ContentMessageContainer extends Component { | @@ -78,12 +79,12 @@ class ContentMessageContainer extends Component { | ||
78 | 79 | ||
79 | 80 | ||
80 | _onRefresh() { | 81 | _onRefresh() { |
81 | - this.props.actions.getContentList(true, 4) | 82 | + this.props.actions.getCommentList(true, this.props.contentListId) |
82 | this.props.actions.getContentType() | 83 | this.props.actions.getContentType() |
83 | } | 84 | } |
84 | 85 | ||
85 | _onEndReached() { | 86 | _onEndReached() { |
86 | - this.props.actions.getContentList(false, 4) | 87 | + this.props.actions.getCommentList(false, this.props.contentListId) |
87 | } | 88 | } |
88 | 89 | ||
89 | _onHiddenTipMessage() { | 90 | _onHiddenTipMessage() { |
@@ -19,6 +19,11 @@ const { | @@ -19,6 +19,11 @@ const { | ||
19 | FETCH_CONTENT_LIST_SUCCESS, | 19 | FETCH_CONTENT_LIST_SUCCESS, |
20 | FETCH_CONTENT_LIST_FAILURE, | 20 | FETCH_CONTENT_LIST_FAILURE, |
21 | 21 | ||
22 | + //main评论内容 | ||
23 | + FETCH_COMMENT_LIST_REQUEST, | ||
24 | + FETCH_COMMENT_LIST_SUCCESS, | ||
25 | + FETCH_COMMENT_LIST_FAILURE, | ||
26 | + | ||
22 | //回复评论 | 27 | //回复评论 |
23 | ADD_ARTICLE_COMMENT_REQUEST, | 28 | ADD_ARTICLE_COMMENT_REQUEST, |
24 | ADD_ARTICLE_COMMENT_SUCCESS, | 29 | ADD_ARTICLE_COMMENT_SUCCESS, |
@@ -83,27 +88,45 @@ export function getContentTypeFailure(error) { | @@ -83,27 +88,45 @@ export function getContentTypeFailure(error) { | ||
83 | } | 88 | } |
84 | } | 89 | } |
85 | 90 | ||
86 | -export function getContentListRequest(isRefresh, isLatest) { | 91 | +export function getCommentListRequest(isRefresh) { |
92 | + return { | ||
93 | + type: FETCH_COMMENT_LIST_REQUEST, | ||
94 | + isRefresh | ||
95 | + }; | ||
96 | +} | ||
97 | + | ||
98 | +export function getCommentListSuccess(json) { | ||
99 | + return { | ||
100 | + type: FETCH_COMMENT_LIST_SUCCESS, | ||
101 | + payload: json, | ||
102 | + } | ||
103 | +} | ||
104 | + | ||
105 | +export function getCommentListFailure(error) { | ||
106 | + return { | ||
107 | + type: FETCH_COMMENT_LIST_FAILURE, | ||
108 | + payload: error, | ||
109 | + } | ||
110 | +} | ||
111 | + | ||
112 | +export function getContentListRequest(isRefresh) { | ||
87 | return { | 113 | return { |
88 | type: FETCH_CONTENT_LIST_REQUEST, | 114 | type: FETCH_CONTENT_LIST_REQUEST, |
89 | - isLatest, | ||
90 | isRefresh | 115 | isRefresh |
91 | }; | 116 | }; |
92 | } | 117 | } |
93 | 118 | ||
94 | -export function getContentListSuccess(json, isLatest) { | 119 | +export function getContentListSuccess(json) { |
95 | return { | 120 | return { |
96 | type: FETCH_CONTENT_LIST_SUCCESS, | 121 | type: FETCH_CONTENT_LIST_SUCCESS, |
97 | payload: json, | 122 | payload: json, |
98 | - isLatest, | ||
99 | } | 123 | } |
100 | } | 124 | } |
101 | 125 | ||
102 | -export function getContentListFailure(error, isLatest) { | 126 | +export function getContentListFailure(error) { |
103 | return { | 127 | return { |
104 | type: FETCH_CONTENT_LIST_FAILURE, | 128 | type: FETCH_CONTENT_LIST_FAILURE, |
105 | payload: error, | 129 | payload: error, |
106 | - isLatest, | ||
107 | } | 130 | } |
108 | } | 131 | } |
109 | 132 | ||
@@ -235,16 +258,58 @@ export function getContentType() { | @@ -235,16 +258,58 @@ export function getContentType() { | ||
235 | } | 258 | } |
236 | 259 | ||
237 | //查询消息 | 260 | //查询消息 |
261 | +export function getCommentList(isRefresh, type) { | ||
262 | + return (dispatch, getState) => { | ||
263 | + let {app, content} = getState(); | ||
264 | + let {isFetching, endReached, currentPage, list} = content.get('commentList').toJS(); | ||
265 | + if (isFetching || (!isRefresh && endReached)) { | ||
266 | + return; | ||
267 | + } | ||
268 | + let oldList = isRefresh ? [] : list | ||
269 | + let processor = ()=> { | ||
270 | + dispatch(getCommentListRequest(isRefresh)); | ||
271 | + return new ContentService(app.host).fetchContentList(isRefresh ? 1 : currentPage + 1, content.pageSize, type) | ||
272 | + .then(json => { | ||
273 | + let payload = parseContentList(json); | ||
274 | + let list = [...oldList, ...payload.list]; | ||
275 | + payload.list = list; | ||
276 | + payload.type = type; | ||
277 | + | ||
278 | + if (payload.currentPage == 1 && payload.list.length == 0) { | ||
279 | + payload.shouldShowEmpty = true; | ||
280 | + } | ||
281 | + dispatch(getCommentListSuccess(payload)); | ||
282 | + }) | ||
283 | + .catch(error => { | ||
284 | + dispatch(getCommentListFailure(error)); | ||
285 | + }); | ||
286 | + } | ||
287 | + ReactNative.NativeModules.YH_CommonHelper.uid() | ||
288 | + .then(uid => { | ||
289 | + processor() | ||
290 | + }) | ||
291 | + .catch(error => { | ||
292 | + ReactNative.NativeModules.YH_CommonHelper.login() | ||
293 | + .then(uid => { | ||
294 | + processor() | ||
295 | + }) | ||
296 | + .catch(error => { | ||
297 | + | ||
298 | + }); | ||
299 | + }); | ||
300 | + }; | ||
301 | +} | ||
302 | + | ||
238 | export function getContentList(isRefresh, type) { | 303 | export function getContentList(isRefresh, type) { |
239 | return (dispatch, getState) => { | 304 | return (dispatch, getState) => { |
240 | let {app, content} = getState(); | 305 | let {app, content} = getState(); |
241 | - let {isFetching, endReached, currentPage, list} = type == 4 ? content.get('commentList').toJS() : content.get('contentList').toJS(); | 306 | + let {isFetching, endReached, currentPage, list} = content.get('contentList').toJS(); |
242 | if (isFetching || (!isRefresh && endReached)) { | 307 | if (isFetching || (!isRefresh && endReached)) { |
243 | return; | 308 | return; |
244 | } | 309 | } |
245 | let oldList = isRefresh ? [] : list | 310 | let oldList = isRefresh ? [] : list |
246 | let processor = ()=> { | 311 | let processor = ()=> { |
247 | - dispatch(getContentListRequest(isRefresh, type == 4)); | 312 | + dispatch(getContentListRequest(isRefresh)); |
248 | return new ContentService(app.host).fetchContentList(isRefresh ? 1 : currentPage + 1, content.pageSize, type) | 313 | return new ContentService(app.host).fetchContentList(isRefresh ? 1 : currentPage + 1, content.pageSize, type) |
249 | .then(json => { | 314 | .then(json => { |
250 | let payload = parseContentList(json); | 315 | let payload = parseContentList(json); |
@@ -255,10 +320,10 @@ export function getContentList(isRefresh, type) { | @@ -255,10 +320,10 @@ export function getContentList(isRefresh, type) { | ||
255 | if (payload.currentPage == 1 && payload.list.length == 0) { | 320 | if (payload.currentPage == 1 && payload.list.length == 0) { |
256 | payload.shouldShowEmpty = true; | 321 | payload.shouldShowEmpty = true; |
257 | } | 322 | } |
258 | - dispatch(getContentListSuccess(payload, type == 4)); | 323 | + dispatch(getContentListSuccess(payload)); |
259 | }) | 324 | }) |
260 | .catch(error => { | 325 | .catch(error => { |
261 | - dispatch(getContentListFailure(error, type == 4)); | 326 | + dispatch(getContentListFailure(error)); |
262 | }); | 327 | }); |
263 | } | 328 | } |
264 | ReactNative.NativeModules.YH_CommonHelper.uid() | 329 | ReactNative.NativeModules.YH_CommonHelper.uid() |
@@ -16,6 +16,11 @@ const { | @@ -16,6 +16,11 @@ const { | ||
16 | FETCH_CONTENT_LIST_SUCCESS, | 16 | FETCH_CONTENT_LIST_SUCCESS, |
17 | FETCH_CONTENT_LIST_FAILURE, | 17 | FETCH_CONTENT_LIST_FAILURE, |
18 | 18 | ||
19 | + //main评论内容 | ||
20 | + FETCH_COMMENT_LIST_REQUEST, | ||
21 | + FETCH_COMMENT_LIST_SUCCESS, | ||
22 | + FETCH_COMMENT_LIST_FAILURE, | ||
23 | + | ||
19 | //回复评论 | 24 | //回复评论 |
20 | ADD_ARTICLE_COMMENT_REQUEST, | 25 | ADD_ARTICLE_COMMENT_REQUEST, |
21 | ADD_ARTICLE_COMMENT_SUCCESS, | 26 | ADD_ARTICLE_COMMENT_SUCCESS, |
@@ -41,10 +46,6 @@ const { | @@ -41,10 +46,6 @@ const { | ||
41 | 46 | ||
42 | const initialState = new InitialState; | 47 | const initialState = new InitialState; |
43 | 48 | ||
44 | -function getContentListObject(isLatest) { | ||
45 | - return isLatest ? 'commentList' : 'contentList'; | ||
46 | -} | ||
47 | - | ||
48 | export default function grassReducer(state=initialState, action) { | 49 | export default function grassReducer(state=initialState, action) { |
49 | switch(action.type) { | 50 | switch(action.type) { |
50 | case SET_CONTENT_LIST_ID: { | 51 | case SET_CONTENT_LIST_ID: { |
@@ -73,29 +74,54 @@ export default function grassReducer(state=initialState, action) { | @@ -73,29 +74,54 @@ export default function grassReducer(state=initialState, action) { | ||
73 | .setIn(['contentType', 'error'], action.payload) | 74 | .setIn(['contentType', 'error'], action.payload) |
74 | } | 75 | } |
75 | 76 | ||
77 | + case FETCH_COMMENT_LIST_REQUEST: { | ||
78 | + return state.setIn(['commentList', 'isFetching'], true) | ||
79 | + .setIn(['commentList', 'isPullToRefresh'], action.isRefresh == true) | ||
80 | + } | ||
81 | + | ||
82 | + case FETCH_COMMENT_LIST_SUCCESS: { | ||
83 | + state = state | ||
84 | + .setIn(['commentList', 'isFetching'], false) | ||
85 | + .setIn(['commentList', 'list'], Immutable.fromJS((action.payload.list))) | ||
86 | + .setIn(['commentList', 'currentPage'], action.payload.currentPage) | ||
87 | + .setIn(['commentList', 'endReached'], action.payload.endReached) | ||
88 | + .setIn(['commentList', 'isPullToRefresh'], false) | ||
89 | + .setIn(['commentList', 'pageCount'], action.payload.pageCount) | ||
90 | + .setIn(['commentList', 'shouldShowEmpty'], action.payload.shouldShowEmpty) | ||
91 | + | ||
92 | + return state; | ||
93 | + } | ||
94 | + | ||
95 | + case FETCH_COMMENT_LIST_FAILURE: { | ||
96 | + return state.setIn(['commentList', 'isFetching'], false) | ||
97 | + .setIn(['commentList', 'isPullToRefresh'], false) | ||
98 | + .setIn(['commentList', 'error'], action.payload) | ||
99 | + .setIn(['commentList', 'shouldShowEmpty'], true); | ||
100 | + } | ||
101 | + | ||
76 | case FETCH_CONTENT_LIST_REQUEST: { | 102 | case FETCH_CONTENT_LIST_REQUEST: { |
77 | - return state.setIn([getContentListObject(action.isLatest), 'isFetching'], true) | ||
78 | - .setIn([getContentListObject(action.isLatest), 'isPullToRefresh'], action.isRefresh == true) | 103 | + return state.setIn(['contentList', 'isFetching'], true) |
104 | + .setIn(['contentList', 'isPullToRefresh'], action.isRefresh == true) | ||
79 | } | 105 | } |
80 | 106 | ||
81 | case FETCH_CONTENT_LIST_SUCCESS: { | 107 | case FETCH_CONTENT_LIST_SUCCESS: { |
82 | state = state | 108 | state = state |
83 | - .setIn([getContentListObject(action.isLatest), 'isFetching'], false) | ||
84 | - .setIn([getContentListObject(action.isLatest), 'list'], Immutable.fromJS((action.payload.list))) | ||
85 | - .setIn([getContentListObject(action.isLatest), 'currentPage'], action.payload.currentPage) | ||
86 | - .setIn([getContentListObject(action.isLatest), 'endReached'], action.payload.endReached) | ||
87 | - .setIn([getContentListObject(action.isLatest), 'isPullToRefresh'], false) | ||
88 | - .setIn([getContentListObject(action.isLatest), 'pageCount'], action.payload.pageCount) | ||
89 | - .setIn([getContentListObject(action.isLatest), 'shouldShowEmpty'], action.payload.shouldShowEmpty) | 109 | + .setIn(['contentList', 'isFetching'], false) |
110 | + .setIn(['contentList', 'list'], Immutable.fromJS((action.payload.list))) | ||
111 | + .setIn(['contentList', 'currentPage'], action.payload.currentPage) | ||
112 | + .setIn(['contentList', 'endReached'], action.payload.endReached) | ||
113 | + .setIn(['contentList', 'isPullToRefresh'], false) | ||
114 | + .setIn(['contentList', 'pageCount'], action.payload.pageCount) | ||
115 | + .setIn(['contentList', 'shouldShowEmpty'], action.payload.shouldShowEmpty) | ||
90 | 116 | ||
91 | return state; | 117 | return state; |
92 | } | 118 | } |
93 | 119 | ||
94 | case FETCH_CONTENT_LIST_FAILURE: { | 120 | case FETCH_CONTENT_LIST_FAILURE: { |
95 | - return state.setIn([getContentListObject(action.isLatest), 'isFetching'], false) | ||
96 | - .setIn([getContentListObject(action.isLatest), 'isPullToRefresh'], false) | ||
97 | - .setIn([getContentListObject(action.isLatest), 'error'], action.payload) | ||
98 | - .setIn([getContentListObject(action.isLatest), 'shouldShowEmpty'], true); | 121 | + return state.setIn(['contentList', 'isFetching'], false) |
122 | + .setIn(['contentList', 'isPullToRefresh'], false) | ||
123 | + .setIn(['contentList', 'error'], action.payload) | ||
124 | + .setIn(['contentList', 'shouldShowEmpty'], true); | ||
99 | } | 125 | } |
100 | 126 | ||
101 | case ADD_ARTICLE_COMMENT_REQUEST: { | 127 | case ADD_ARTICLE_COMMENT_REQUEST: { |
-
Please register or login to post a comment