...
|
...
|
@@ -43,6 +43,44 @@ const { |
|
|
SET_GOOESGROUP_FILTER,
|
|
|
SET_GOOESGROUP_Y,
|
|
|
|
|
|
//获取资讯评论列表
|
|
|
GET_COMMENTS_LIST_REQUEST,
|
|
|
GET_COMMENTS_LIST_SUCCESS,
|
|
|
GET_COMMENTS_LIST_FAILURE,
|
|
|
|
|
|
//资讯添加评论
|
|
|
ADD_COMMENTS_FOR_ARTIVLE_REQUEST,
|
|
|
ADD_COMMENTS_FOR_ARTIVLE_SUCCESS,
|
|
|
ADD_COMMENTS_FOR_ARTIVLE_FAILURE,
|
|
|
|
|
|
//资讯内容点赞
|
|
|
ADD_PRAISE_FOR_COMMENTS_REQUEST,
|
|
|
ADD_PRAISE_FOR_COMMENTS_SUCCESS,
|
|
|
ADD_PRAISE_FOR_COMMENTS_FAILURE,
|
|
|
|
|
|
//文章点赞Info
|
|
|
GET_PRAISE_FOR_ARTIVLE_REQUEST,
|
|
|
GET_PRAISE_FOR_ARTIVLE_SUCCESS,
|
|
|
GET_PRAISE_FOR_ARTIVLE_FAILURE,
|
|
|
|
|
|
SET_PRAISE_FOR_COMMENTS,
|
|
|
|
|
|
//点赞文章
|
|
|
PRAISE_FOR_ARTIVLE_REQUEST,
|
|
|
PRAISE_FOR_ARTIVLE_SUCCESS,
|
|
|
PRAISE_FOR_ARTIVLE_FAILURE,
|
|
|
//取消点赞文章
|
|
|
CANCEL_PRAISE_FOR_ARTIVLE_REQUEST,
|
|
|
CANCEL_PRAISE_FOR_ARTIVLE_SUCCESS,
|
|
|
CANCEL_PRAISE_FOR_ARTIVLE_FAILURE,
|
|
|
//收藏
|
|
|
ADD_FAVORITE_REQUEST,
|
|
|
ADD_FAVORITE_SUCCESS,
|
|
|
ADD_FAVORITE_FAILURE,
|
|
|
//取消收藏
|
|
|
CANCEL_FAVORITE_REQUEST,
|
|
|
CANCEL_FAVORITE_SUCCESS,
|
|
|
CANCEL_FAVORITE_FAILURE,
|
|
|
} = require('../../constants/actionTypes').default;
|
|
|
|
|
|
export function setArticleId(id) {
|
...
|
...
|
@@ -674,3 +712,419 @@ function parseWeChatData(json) { |
|
|
wechatCopy,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function getCommentsListRequest() {
|
|
|
return {
|
|
|
type: GET_COMMENTS_LIST_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function getCommentsListSuccess(json) {
|
|
|
return {
|
|
|
type: GET_COMMENTS_LIST_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function getCommentsListFailure(error) {
|
|
|
return {
|
|
|
type: GET_COMMENTS_LIST_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function getCommentsList() {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, detail} = getState();
|
|
|
let {articleId, article,commentsList} = detail;
|
|
|
let page = commentsList.page;
|
|
|
let list = commentsList.data;
|
|
|
let limit = commentsList.limit;
|
|
|
let total_page = commentsList.total_page;
|
|
|
if (list && list.length > 0 && total_page <= page) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
dispatch(getCommentsListRequest());
|
|
|
return new DetailService(app.serviceHost).getCommentsList(articleId,page,limit)
|
|
|
.then(json => {
|
|
|
let param = parseCommentsData(json)
|
|
|
dispatch(getCommentsListSuccess(param));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(getCommentsListFailure(error));
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function parseCommentsData(json) {
|
|
|
let data = [];
|
|
|
let page = 1;
|
|
|
let total = 0;
|
|
|
let total_page = 0;
|
|
|
|
|
|
if (json) {
|
|
|
data = json.list;
|
|
|
page = json.page;
|
|
|
total = json.total;
|
|
|
total_page = json.total_page;
|
|
|
}
|
|
|
return {
|
|
|
data,
|
|
|
page,
|
|
|
total,
|
|
|
total_page,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
function addCommentsForArtivleRequest() {
|
|
|
return {
|
|
|
type: ADD_COMMENTS_FOR_ARTIVLE_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function addCommentsForArtivleSuccess(json) {
|
|
|
return {
|
|
|
type: ADD_COMMENTS_FOR_ARTIVLE_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function addCommentsForArtivleFailure(error) {
|
|
|
return {
|
|
|
type: ADD_COMMENTS_FOR_ARTIVLE_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function addCommentsForArtivle(content,replyTo) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, detail} = getState();
|
|
|
let {articleId, article} = detail;
|
|
|
let article_id = articleId;
|
|
|
|
|
|
let fetchInfo = (article_id,uid) => {
|
|
|
dispatch(addCommentsForArtivleRequest());
|
|
|
return new DetailService(app.serviceHost).addCommentsForArtivle(article_id,uid,content,replyTo)
|
|
|
.then(json => {
|
|
|
dispatch(addCommentsForArtivleSuccess(json));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(addCommentsForArtivleFailure(error));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
ReactNative.NativeModules.YH_CommonHelper.uid()
|
|
|
.then(uid => {
|
|
|
fetchInfo(article_id,uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
ReactNative.NativeModules.YH_CommonHelper.login()
|
|
|
.then(uid => {
|
|
|
fetchInfo(article_id,uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function setPraiseForCommentsReq(json) {
|
|
|
return {
|
|
|
type: SET_PRAISE_FOR_COMMENTS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function setPraiseForComments(comment_id,praise) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, detail} = getState();
|
|
|
let {commentsList} = detail;
|
|
|
let comments = commentsList?commentsList.toJS():null;
|
|
|
let list = comments?comments.data:null;
|
|
|
list && list.map((item, i) => {
|
|
|
if (comment_id == item.id) {
|
|
|
item.isPraise = praise;
|
|
|
let num = item.praiseNum?item.praiseNum:0;
|
|
|
if (praise === 'Y') {
|
|
|
item.praiseNum = num + 1;
|
|
|
}else {
|
|
|
item.praiseNum = num - 1 <= 0 ? 0 : num - 1;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
dispatch(setPraiseForCommentsReq(list));
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function addPraiseForCommentsRequest() {
|
|
|
return {
|
|
|
type: ADD_PRAISE_FOR_COMMENTS_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function addPraiseForCommentsSuccess(json) {
|
|
|
return {
|
|
|
type: ADD_PRAISE_FOR_COMMENTS_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function addPraiseForCommentsFailure(error) {
|
|
|
return {
|
|
|
type: ADD_PRAISE_FOR_COMMENTS_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function addPraiseForComments(comment_id,praise) {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, detail} = getState();
|
|
|
let {articleId, article} = detail;
|
|
|
let article_id = articleId;
|
|
|
|
|
|
dispatch(addPraiseForCommentsRequest());
|
|
|
return new DetailService(app.serviceHost).addPraiseForComments(comment_id,praise,article_id)
|
|
|
.then(json => {
|
|
|
dispatch(addPraiseForCommentsSuccess(json));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(addPraiseForCommentsFailure(error));
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function getPraiseForArtivleRequest() {
|
|
|
return {
|
|
|
type: GET_PRAISE_FOR_ARTIVLE_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function getPraiseForArtivleSuccess(json) {
|
|
|
return {
|
|
|
type: GET_PRAISE_FOR_ARTIVLE_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function getPraiseForArtivleFailure(error) {
|
|
|
return {
|
|
|
type: GET_PRAISE_FOR_ARTIVLE_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function getPraiseForArtivle() {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, detail} = getState();
|
|
|
let {articleId, article} = detail;
|
|
|
let id = articleId;
|
|
|
|
|
|
let fetchInfo = (id,uid) => {
|
|
|
dispatch(getPraiseForArtivleRequest());
|
|
|
return new DetailService(app.serviceHost).getPraiseForArtivle(uid,id)
|
|
|
.then(json => {
|
|
|
dispatch(getPraiseForArtivleSuccess(json));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(getPraiseForArtivleFailure(error));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
ReactNative.NativeModules.YH_CommonHelper.uid()
|
|
|
.then(uid => {
|
|
|
fetchInfo(id,uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
ReactNative.NativeModules.YH_CommonHelper.login()
|
|
|
.then(uid => {
|
|
|
fetchInfo(id,uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function praiseForArtivleRequest() {
|
|
|
return {
|
|
|
type: PRAISE_FOR_ARTIVLE_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function praiseForArtivleSuccess(json) {
|
|
|
return {
|
|
|
type: PRAISE_FOR_ARTIVLE_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function praiseForArtivleFailure(error) {
|
|
|
return {
|
|
|
type: PRAISE_FOR_ARTIVLE_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function praiseForArtivle() {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, detail} = getState();
|
|
|
let {articleId, article} = detail;
|
|
|
let article_id = articleId;
|
|
|
|
|
|
dispatch(praiseForArtivleRequest());
|
|
|
return new DetailService(app.serviceHost).praiseForArtivle(article_id)
|
|
|
.then(json => {
|
|
|
dispatch(praiseForArtivleSuccess(json));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(praiseForArtivleFailure(error));
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function cancelPraiseForArtivleRequest() {
|
|
|
return {
|
|
|
type: CANCEL_PRAISE_FOR_ARTIVLE_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function cancelPraiseForArtivleSuccess(json) {
|
|
|
return {
|
|
|
type: CANCEL_PRAISE_FOR_ARTIVLE_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function cancelPraiseForArtivleFailure(error) {
|
|
|
return {
|
|
|
type: CANCEL_PRAISE_FOR_ARTIVLE_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function cancelPraiseForArtivle() {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, detail} = getState();
|
|
|
let {articleId, article} = detail;
|
|
|
let article_id = articleId;
|
|
|
|
|
|
dispatch(cancelPraiseForArtivleRequest());
|
|
|
return new DetailService(app.serviceHost).cancelPraiseForArtivle(article_id)
|
|
|
.then(json => {
|
|
|
dispatch(cancelPraiseForArtivleSuccess(json));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(cancelPraiseForArtivleFailure(error));
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function addFavoriteRequest() {
|
|
|
return {
|
|
|
type: ADD_FAVORITE_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function addFavoriteSuccess(json) {
|
|
|
return {
|
|
|
type: ADD_FAVORITE_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function addFavoriteFailure(error) {
|
|
|
return {
|
|
|
type: ADD_FAVORITE_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function addFavorite() {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, detail} = getState();
|
|
|
let {articleId, article} = detail;
|
|
|
let article_id = articleId;
|
|
|
|
|
|
let fetchInfo = (article_id,uid) => {
|
|
|
dispatch(addFavoriteRequest());
|
|
|
return new DetailService(app.serviceHost).addFavorite(uid,article_id)
|
|
|
.then(json => {
|
|
|
dispatch(addFavoriteSuccess(json));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(addFavoriteFailure(error));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
ReactNative.NativeModules.YH_CommonHelper.uid()
|
|
|
.then(uid => {
|
|
|
fetchInfo(article_id,uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
ReactNative.NativeModules.YH_CommonHelper.login()
|
|
|
.then(uid => {
|
|
|
fetchInfo(article_id,uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function cancelFavoriteRequest() {
|
|
|
return {
|
|
|
type: CANCEL_FAVORITE_REQUEST,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function cancelFavoriteSuccess(json) {
|
|
|
return {
|
|
|
type: CANCEL_FAVORITE_SUCCESS,
|
|
|
payload: json
|
|
|
};
|
|
|
}
|
|
|
|
|
|
function cancelFavoriteFailure(error) {
|
|
|
return {
|
|
|
type: CANCEL_FAVORITE_FAILURE,
|
|
|
payload: error
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function cancelFavorite() {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, detail} = getState();
|
|
|
let {articleId, article} = detail;
|
|
|
let article_id = articleId;
|
|
|
|
|
|
let fetchInfo = (article_id,uid) => {
|
|
|
dispatch(cancelFavoriteRequest());
|
|
|
return new DetailService(app.serviceHost).cancelFavorite(uid,article_id)
|
|
|
.then(json => {
|
|
|
dispatch(cancelFavoriteSuccess(json));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(cancelFavoriteFailure(error));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
ReactNative.NativeModules.YH_CommonHelper.uid()
|
|
|
.then(uid => {
|
|
|
fetchInfo(article_id,uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
ReactNative.NativeModules.YH_CommonHelper.login()
|
|
|
.then(uid => {
|
|
|
fetchInfo(article_id,uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
});
|
|
|
};
|
|
|
} |
...
|
...
|
|