Showing
4 changed files
with
70 additions
and
21 deletions
@@ -24,34 +24,17 @@ export default class List extends Component { | @@ -24,34 +24,17 @@ export default class List extends Component { | ||
24 | super(props); | 24 | super(props); |
25 | this.renderRow = this.renderRow.bind(this); | 25 | this.renderRow = this.renderRow.bind(this); |
26 | this.renderHeader = this.renderHeader.bind(this); | 26 | this.renderHeader = this.renderHeader.bind(this); |
27 | - this.state = { | ||
28 | - author: null, | ||
29 | - }; | ||
30 | this.dataSource = new ListView.DataSource({ | 27 | this.dataSource = new ListView.DataSource({ |
31 | rowHasChanged: (r1, r2) => !Immutable.is(r1, r2), | 28 | rowHasChanged: (r1, r2) => !Immutable.is(r1, r2), |
32 | sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2), | 29 | sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2), |
33 | }); | 30 | }); |
34 | } | 31 | } |
35 | 32 | ||
36 | - componentDidMount() { | ||
37 | - let {list} = this.props.data.toJS().articles; | ||
38 | - if (list&&list.length) { | ||
39 | - let author = list[0].author; | ||
40 | - this.setState({author}); | ||
41 | - } | ||
42 | - } | ||
43 | - componentWillReceiveProps(nextProps){ | ||
44 | - let {list} = nextProps.data.toJS().articles; | ||
45 | - if (list&&list.length) { | ||
46 | - let author = list[0].author; | ||
47 | - this.setState({author}); | ||
48 | - } | ||
49 | - } | ||
50 | - | ||
51 | renderHeader() { | 33 | renderHeader() { |
52 | if (this.props.data.type == 'editor') { | 34 | if (this.props.data.type == 'editor') { |
35 | + let author = this.props.data.get('author').toJS(); | ||
53 | return( | 36 | return( |
54 | - <HeaderCell resource={this.state.author}/> | 37 | + <HeaderCell resource={author.data}/> |
55 | ); | 38 | ); |
56 | } else { | 39 | } else { |
57 | return null; | 40 | return null; |
@@ -63,6 +63,7 @@ class ListContainer extends Component { | @@ -63,6 +63,7 @@ class ListContainer extends Component { | ||
63 | } | 63 | } |
64 | 64 | ||
65 | componentDidMount() { | 65 | componentDidMount() { |
66 | + this.props.actions.getAuthor(); | ||
66 | this.props.actions.getArticleList(); | 67 | this.props.actions.getArticleList(); |
67 | } | 68 | } |
68 | 69 | ||
@@ -94,6 +95,7 @@ class ListContainer extends Component { | @@ -94,6 +95,7 @@ class ListContainer extends Component { | ||
94 | } | 95 | } |
95 | 96 | ||
96 | _onEndReached() { | 97 | _onEndReached() { |
98 | + console.log('aaaaaaa'); | ||
97 | InteractionManager.runAfterInteractions(() => { | 99 | InteractionManager.runAfterInteractions(() => { |
98 | this.props.actions.getArticleList(); | 100 | this.props.actions.getArticleList(); |
99 | }); | 101 | }); |
@@ -101,8 +103,6 @@ class ListContainer extends Component { | @@ -101,8 +103,6 @@ class ListContainer extends Component { | ||
101 | 103 | ||
102 | render() { | 104 | render() { |
103 | let {list} = this.props; | 105 | let {list} = this.props; |
104 | - console.log('aaaaa'); | ||
105 | - console.log(this.props); | ||
106 | return ( | 106 | return ( |
107 | <View style={styles.container}> | 107 | <View style={styles.container}> |
108 | <List | 108 | <List |
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | 2 | ||
3 | import ReactNative from 'react-native'; | 3 | import ReactNative from 'react-native'; |
4 | import ListService from '../../services/ListService'; | 4 | import ListService from '../../services/ListService'; |
5 | +import DetailService from '../../services/DetailService'; | ||
5 | 6 | ||
6 | const { | 7 | const { |
7 | SET_LIST_TYPE, | 8 | SET_LIST_TYPE, |
@@ -13,6 +14,10 @@ const { | @@ -13,6 +14,10 @@ const { | ||
13 | GET_ARTICLE_LIST_FAILURE, | 14 | GET_ARTICLE_LIST_FAILURE, |
14 | 15 | ||
15 | LIKE_ARTICLE, | 16 | LIKE_ARTICLE, |
17 | + | ||
18 | + GET_AUTHOR_REQUEST, | ||
19 | + GET_AUTHOR_SUCCESS, | ||
20 | + GET_AUTHOR_FAILURE, | ||
16 | } = require('../../constants/actionTypes').default; | 21 | } = require('../../constants/actionTypes').default; |
17 | 22 | ||
18 | export function setListType(type) { | 23 | export function setListType(type) { |
@@ -169,3 +174,46 @@ function parseArticleList(json) { | @@ -169,3 +174,46 @@ function parseArticleList(json) { | ||
169 | total, | 174 | total, |
170 | }; | 175 | }; |
171 | } | 176 | } |
177 | + | ||
178 | +function getAuthorRequest() { | ||
179 | + return { | ||
180 | + type: GET_AUTHOR_REQUEST, | ||
181 | + }; | ||
182 | +} | ||
183 | + | ||
184 | +function getAuthorSuccess(json) { | ||
185 | + return { | ||
186 | + type: GET_AUTHOR_SUCCESS, | ||
187 | + payload: json | ||
188 | + }; | ||
189 | +} | ||
190 | + | ||
191 | +function getAuthorFailure(error) { | ||
192 | + return { | ||
193 | + type: GET_AUTHOR_FAILURE, | ||
194 | + payload: error | ||
195 | + }; | ||
196 | +} | ||
197 | + | ||
198 | +export function getAuthor() { | ||
199 | + return (dispatch, getState) => { | ||
200 | + let {app, list} = getState(); | ||
201 | + let {type, authorId, tag, articles} = list; | ||
202 | + | ||
203 | + if (!authorId) { | ||
204 | + return; | ||
205 | + } | ||
206 | + | ||
207 | + dispatch(getAuthorRequest()); | ||
208 | + return new DetailService(app.serviceHost).getAuthor(authorId) | ||
209 | + .then(json => { | ||
210 | + let payload = json; | ||
211 | + | ||
212 | + dispatch(getAuthorSuccess(json)); | ||
213 | + // dispatch(dataExposure(payload.logFloors)); | ||
214 | + }) | ||
215 | + .catch(error => { | ||
216 | + dispatch(getAuthorFailure(error)); | ||
217 | + }); | ||
218 | + }; | ||
219 | +} |
@@ -14,6 +14,9 @@ const { | @@ -14,6 +14,9 @@ const { | ||
14 | 14 | ||
15 | LIKE_ARTICLE, | 15 | LIKE_ARTICLE, |
16 | 16 | ||
17 | + GET_AUTHOR_REQUEST, | ||
18 | + GET_AUTHOR_SUCCESS, | ||
19 | + GET_AUTHOR_FAILURE, | ||
17 | } = require('../../constants/actionTypes').default; | 20 | } = require('../../constants/actionTypes').default; |
18 | 21 | ||
19 | const initialState = new InitialState; | 22 | const initialState = new InitialState; |
@@ -81,7 +84,22 @@ export default function listReducer(state=initialState, action) { | @@ -81,7 +84,22 @@ export default function listReducer(state=initialState, action) { | ||
81 | return state.setIn(['articles', 'isFetching'], false) | 84 | return state.setIn(['articles', 'isFetching'], false) |
82 | .setIn(['articles', 'error'], action.payload) | 85 | .setIn(['articles', 'error'], action.payload) |
83 | } | 86 | } |
87 | + | ||
88 | + case GET_AUTHOR_REQUEST: { | ||
89 | + return state.setIn(['author', 'isFetching'], true) | ||
90 | + .setIn(['author', 'error'], null); | ||
91 | + } | ||
92 | + | ||
93 | + case GET_AUTHOR_SUCCESS: { | ||
94 | + return state.setIn(['author', 'isFetching'], false) | ||
95 | + .setIn(['author', 'error'], null) | ||
96 | + .setIn(['author', 'data'], Immutable.fromJS(action.payload)); | ||
97 | + } | ||
84 | 98 | ||
99 | + case GET_AUTHOR_FAILURE: { | ||
100 | + return state.setIn(['author', 'isFetching'], false) | ||
101 | + .setIn(['author', 'error'], action.payload); | ||
102 | + } | ||
85 | } | 103 | } |
86 | 104 | ||
87 | return state; | 105 | return state; |
-
Please register or login to post a comment