Authored by Kennaki

重新请求作者信息。

... ... @@ -24,34 +24,17 @@ export default class List extends Component {
super(props);
this.renderRow = this.renderRow.bind(this);
this.renderHeader = this.renderHeader.bind(this);
this.state = {
author: null,
};
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2),
});
}
componentDidMount() {
let {list} = this.props.data.toJS().articles;
if (list&&list.length) {
let author = list[0].author;
this.setState({author});
}
}
componentWillReceiveProps(nextProps){
let {list} = nextProps.data.toJS().articles;
if (list&&list.length) {
let author = list[0].author;
this.setState({author});
}
}
renderHeader() {
if (this.props.data.type == 'editor') {
let author = this.props.data.get('author').toJS();
return(
<HeaderCell resource={this.state.author}/>
<HeaderCell resource={author.data}/>
);
} else {
return null;
... ...
... ... @@ -63,6 +63,7 @@ class ListContainer extends Component {
}
componentDidMount() {
this.props.actions.getAuthor();
this.props.actions.getArticleList();
}
... ... @@ -94,6 +95,7 @@ class ListContainer extends Component {
}
_onEndReached() {
console.log('aaaaaaa');
InteractionManager.runAfterInteractions(() => {
this.props.actions.getArticleList();
});
... ... @@ -101,8 +103,6 @@ class ListContainer extends Component {
render() {
let {list} = this.props;
console.log('aaaaa');
console.log(this.props);
return (
<View style={styles.container}>
<List
... ...
... ... @@ -2,6 +2,7 @@
import ReactNative from 'react-native';
import ListService from '../../services/ListService';
import DetailService from '../../services/DetailService';
const {
SET_LIST_TYPE,
... ... @@ -13,6 +14,10 @@ const {
GET_ARTICLE_LIST_FAILURE,
LIKE_ARTICLE,
GET_AUTHOR_REQUEST,
GET_AUTHOR_SUCCESS,
GET_AUTHOR_FAILURE,
} = require('../../constants/actionTypes').default;
export function setListType(type) {
... ... @@ -169,3 +174,46 @@ function parseArticleList(json) {
total,
};
}
function getAuthorRequest() {
return {
type: GET_AUTHOR_REQUEST,
};
}
function getAuthorSuccess(json) {
return {
type: GET_AUTHOR_SUCCESS,
payload: json
};
}
function getAuthorFailure(error) {
return {
type: GET_AUTHOR_FAILURE,
payload: error
};
}
export function getAuthor() {
return (dispatch, getState) => {
let {app, list} = getState();
let {type, authorId, tag, articles} = list;
if (!authorId) {
return;
}
dispatch(getAuthorRequest());
return new DetailService(app.serviceHost).getAuthor(authorId)
.then(json => {
let payload = json;
dispatch(getAuthorSuccess(json));
// dispatch(dataExposure(payload.logFloors));
})
.catch(error => {
dispatch(getAuthorFailure(error));
});
};
}
... ...
... ... @@ -14,6 +14,9 @@ const {
LIKE_ARTICLE,
GET_AUTHOR_REQUEST,
GET_AUTHOR_SUCCESS,
GET_AUTHOR_FAILURE,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
... ... @@ -81,7 +84,22 @@ export default function listReducer(state=initialState, action) {
return state.setIn(['articles', 'isFetching'], false)
.setIn(['articles', 'error'], action.payload)
}
case GET_AUTHOR_REQUEST: {
return state.setIn(['author', 'isFetching'], true)
.setIn(['author', 'error'], null);
}
case GET_AUTHOR_SUCCESS: {
return state.setIn(['author', 'isFetching'], false)
.setIn(['author', 'error'], null)
.setIn(['author', 'data'], Immutable.fromJS(action.payload));
}
case GET_AUTHOR_FAILURE: {
return state.setIn(['author', 'isFetching'], false)
.setIn(['author', 'error'], action.payload);
}
}
return state;
... ...