Authored by 张文文

bug fix

... ... @@ -17,7 +17,6 @@ export default class ContentListView extends Component {
constructor(props) {
super(props);
this.trigggePullToRefresh = this.trigggePullToRefresh.bind(this);
this._renderRow = this._renderRow.bind(this);
this._renderFooter = this._renderFooter.bind(this);
this.dataSource = new ListView.DataSource({
... ... @@ -25,19 +24,6 @@ export default class ContentListView extends Component {
});
}
componentDidMount() {
this.trigggePullToRefresh();
}
trigggePullToRefresh() {
if (Platform.OS === 'ios') {
InteractionManager.runAfterInteractions(() => {
this.listView && this.listView.getScrollResponder().startPullToRefresh();
});
} else {
this.props.onRefresh && this.props.onRefresh();
}
}
_renderFooter(){
return (
... ...
... ... @@ -17,7 +17,6 @@ export default class ContentMessageView extends Component {
super(props);
this._renderRow = this._renderRow.bind(this);
this.trigggePullToRefresh = this.trigggePullToRefresh.bind(this);
this._renderHeader = this._renderHeader.bind(this);
this._renderFooter = this._renderFooter.bind(this);
this.dataSource = new ListView.DataSource({
... ... @@ -25,10 +24,6 @@ export default class ContentMessageView extends Component {
});
}
componentDidMount() {
this.trigggePullToRefresh();
}
_renderRow(rowData, sectionID, rowID) {
let showLine = this.props.commentList.length === +rowID+1 ? false : true;
return (
... ... @@ -100,16 +95,6 @@ export default class ContentMessageView extends Component {
)
}
trigggePullToRefresh() {
if (Platform.OS === 'ios') {
InteractionManager.runAfterInteractions(() => {
this.listView && this.listView.getScrollResponder().startPullToRefresh();
});
} else {
this.props.onRefresh && this.props.onRefresh();
}
}
render() {
let {commentList, isPullToRefresh, tipMessage} = this.props;
... ...
... ... @@ -41,6 +41,10 @@ export default keyMirror({
FETCH_CONTENT_LIST_SUCCESS: null,
FETCH_CONTENT_LIST_FAILURE: null,
FETCH_COMMENT_LIST_REQUEST: null,
FETCH_COMMENT_LIST_SUCCESS: null,
FETCH_COMMENT_LIST_FAILURE: null,
//回复评论
ADD_ARTICLE_COMMENT_REQUEST: null,
ADD_ARTICLE_COMMENT_SUCCESS: null,
... ...
... ... @@ -66,7 +66,7 @@ class ContentListContainer extends Component {
}
componentDidMount() {
// this.props.actions.getContentList(true, this.props.contentListId)
this.props.actions.getContentList(false, this.props.contentListId)
}
componentWillUnmount() {
... ...
... ... @@ -21,6 +21,7 @@ const actions = [
function mapStateToProps(state) {
return {
contentListId: state.content.contentListId,
tabButtons: state.content.contentType.get('list').toJS(),
commentList: state.content.commentList.get('list').toJS(),
isPullToRefresh: state.content.commentList.get('isPullToRefresh'),
... ... @@ -67,8 +68,8 @@ class ContentMessageContainer extends Component {
}
componentDidMount() {
// this.props.actions.getContentList(true, 4)
// this.props.actions.getContentType()
this.props.actions.getCommentList(false, this.props.contentListId)
this.props.actions.getContentType()
}
componentWillUnmount() {
... ... @@ -78,12 +79,12 @@ class ContentMessageContainer extends Component {
_onRefresh() {
this.props.actions.getContentList(true, 4)
this.props.actions.getCommentList(true, this.props.contentListId)
this.props.actions.getContentType()
}
_onEndReached() {
this.props.actions.getContentList(false, 4)
this.props.actions.getCommentList(false, this.props.contentListId)
}
_onHiddenTipMessage() {
... ...
... ... @@ -19,6 +19,11 @@ const {
FETCH_CONTENT_LIST_SUCCESS,
FETCH_CONTENT_LIST_FAILURE,
//main评论内容
FETCH_COMMENT_LIST_REQUEST,
FETCH_COMMENT_LIST_SUCCESS,
FETCH_COMMENT_LIST_FAILURE,
//回复评论
ADD_ARTICLE_COMMENT_REQUEST,
ADD_ARTICLE_COMMENT_SUCCESS,
... ... @@ -83,27 +88,45 @@ export function getContentTypeFailure(error) {
}
}
export function getContentListRequest(isRefresh, isLatest) {
export function getCommentListRequest(isRefresh) {
return {
type: FETCH_COMMENT_LIST_REQUEST,
isRefresh
};
}
export function getCommentListSuccess(json) {
return {
type: FETCH_COMMENT_LIST_SUCCESS,
payload: json,
}
}
export function getCommentListFailure(error) {
return {
type: FETCH_COMMENT_LIST_FAILURE,
payload: error,
}
}
export function getContentListRequest(isRefresh) {
return {
type: FETCH_CONTENT_LIST_REQUEST,
isLatest,
isRefresh
};
}
export function getContentListSuccess(json, isLatest) {
export function getContentListSuccess(json) {
return {
type: FETCH_CONTENT_LIST_SUCCESS,
payload: json,
isLatest,
}
}
export function getContentListFailure(error, isLatest) {
export function getContentListFailure(error) {
return {
type: FETCH_CONTENT_LIST_FAILURE,
payload: error,
isLatest,
}
}
... ... @@ -235,16 +258,58 @@ export function getContentType() {
}
//查询消息
export function getCommentList(isRefresh, type) {
return (dispatch, getState) => {
let {app, content} = getState();
let {isFetching, endReached, currentPage, list} = content.get('commentList').toJS();
if (isFetching || (!isRefresh && endReached)) {
return;
}
let oldList = isRefresh ? [] : list
let processor = ()=> {
dispatch(getCommentListRequest(isRefresh));
return new ContentService(app.host).fetchContentList(isRefresh ? 1 : currentPage + 1, content.pageSize, type)
.then(json => {
let payload = parseContentList(json);
let list = [...oldList, ...payload.list];
payload.list = list;
payload.type = type;
if (payload.currentPage == 1 && payload.list.length == 0) {
payload.shouldShowEmpty = true;
}
dispatch(getCommentListSuccess(payload));
})
.catch(error => {
dispatch(getCommentListFailure(error));
});
}
ReactNative.NativeModules.YH_CommonHelper.uid()
.then(uid => {
processor()
})
.catch(error => {
ReactNative.NativeModules.YH_CommonHelper.login()
.then(uid => {
processor()
})
.catch(error => {
});
});
};
}
export function getContentList(isRefresh, type) {
return (dispatch, getState) => {
let {app, content} = getState();
let {isFetching, endReached, currentPage, list} = type == 4 ? content.get('commentList').toJS() : content.get('contentList').toJS();
let {isFetching, endReached, currentPage, list} = content.get('contentList').toJS();
if (isFetching || (!isRefresh && endReached)) {
return;
}
let oldList = isRefresh ? [] : list
let processor = ()=> {
dispatch(getContentListRequest(isRefresh, type == 4));
dispatch(getContentListRequest(isRefresh));
return new ContentService(app.host).fetchContentList(isRefresh ? 1 : currentPage + 1, content.pageSize, type)
.then(json => {
let payload = parseContentList(json);
... ... @@ -255,10 +320,10 @@ export function getContentList(isRefresh, type) {
if (payload.currentPage == 1 && payload.list.length == 0) {
payload.shouldShowEmpty = true;
}
dispatch(getContentListSuccess(payload, type == 4));
dispatch(getContentListSuccess(payload));
})
.catch(error => {
dispatch(getContentListFailure(error, type == 4));
dispatch(getContentListFailure(error));
});
}
ReactNative.NativeModules.YH_CommonHelper.uid()
... ...
... ... @@ -16,6 +16,11 @@ const {
FETCH_CONTENT_LIST_SUCCESS,
FETCH_CONTENT_LIST_FAILURE,
//main评论内容
FETCH_COMMENT_LIST_REQUEST,
FETCH_COMMENT_LIST_SUCCESS,
FETCH_COMMENT_LIST_FAILURE,
//回复评论
ADD_ARTICLE_COMMENT_REQUEST,
ADD_ARTICLE_COMMENT_SUCCESS,
... ... @@ -41,10 +46,6 @@ const {
const initialState = new InitialState;
function getContentListObject(isLatest) {
return isLatest ? 'commentList' : 'contentList';
}
export default function grassReducer(state=initialState, action) {
switch(action.type) {
case SET_CONTENT_LIST_ID: {
... ... @@ -73,29 +74,54 @@ export default function grassReducer(state=initialState, action) {
.setIn(['contentType', 'error'], action.payload)
}
case FETCH_COMMENT_LIST_REQUEST: {
return state.setIn(['commentList', 'isFetching'], true)
.setIn(['commentList', 'isPullToRefresh'], action.isRefresh == true)
}
case FETCH_COMMENT_LIST_SUCCESS: {
state = state
.setIn(['commentList', 'isFetching'], false)
.setIn(['commentList', 'list'], Immutable.fromJS((action.payload.list)))
.setIn(['commentList', 'currentPage'], action.payload.currentPage)
.setIn(['commentList', 'endReached'], action.payload.endReached)
.setIn(['commentList', 'isPullToRefresh'], false)
.setIn(['commentList', 'pageCount'], action.payload.pageCount)
.setIn(['commentList', 'shouldShowEmpty'], action.payload.shouldShowEmpty)
return state;
}
case FETCH_COMMENT_LIST_FAILURE: {
return state.setIn(['commentList', 'isFetching'], false)
.setIn(['commentList', 'isPullToRefresh'], false)
.setIn(['commentList', 'error'], action.payload)
.setIn(['commentList', 'shouldShowEmpty'], true);
}
case FETCH_CONTENT_LIST_REQUEST: {
return state.setIn([getContentListObject(action.isLatest), 'isFetching'], true)
.setIn([getContentListObject(action.isLatest), 'isPullToRefresh'], action.isRefresh == true)
return state.setIn(['contentList', 'isFetching'], true)
.setIn(['contentList', 'isPullToRefresh'], action.isRefresh == true)
}
case FETCH_CONTENT_LIST_SUCCESS: {
state = state
.setIn([getContentListObject(action.isLatest), 'isFetching'], false)
.setIn([getContentListObject(action.isLatest), 'list'], Immutable.fromJS((action.payload.list)))
.setIn([getContentListObject(action.isLatest), 'currentPage'], action.payload.currentPage)
.setIn([getContentListObject(action.isLatest), 'endReached'], action.payload.endReached)
.setIn([getContentListObject(action.isLatest), 'isPullToRefresh'], false)
.setIn([getContentListObject(action.isLatest), 'pageCount'], action.payload.pageCount)
.setIn([getContentListObject(action.isLatest), 'shouldShowEmpty'], action.payload.shouldShowEmpty)
.setIn(['contentList', 'isFetching'], false)
.setIn(['contentList', 'list'], Immutable.fromJS((action.payload.list)))
.setIn(['contentList', 'currentPage'], action.payload.currentPage)
.setIn(['contentList', 'endReached'], action.payload.endReached)
.setIn(['contentList', 'isPullToRefresh'], false)
.setIn(['contentList', 'pageCount'], action.payload.pageCount)
.setIn(['contentList', 'shouldShowEmpty'], action.payload.shouldShowEmpty)
return state;
}
case FETCH_CONTENT_LIST_FAILURE: {
return state.setIn([getContentListObject(action.isLatest), 'isFetching'], false)
.setIn([getContentListObject(action.isLatest), 'isPullToRefresh'], false)
.setIn([getContentListObject(action.isLatest), 'error'], action.payload)
.setIn([getContentListObject(action.isLatest), 'shouldShowEmpty'], true);
return state.setIn(['contentList', 'isFetching'], false)
.setIn(['contentList', 'isPullToRefresh'], false)
.setIn(['contentList', 'error'], action.payload)
.setIn(['contentList', 'shouldShowEmpty'], true);
}
case ADD_ARTICLE_COMMENT_REQUEST: {
... ...