Authored by chenl

Merge branch '5.8.0-0.44.0' of http://git.yoho.cn/mobile/YH_RNComponent into 5.8.0-0.44.0

... ... @@ -24,27 +24,46 @@ export default class Comments extends React.Component {
}
render() {
let url = 'http://head.static.yhbimg.com/yhb-head/2015/11/27/10/02497688cb0268347d08ce3df52af8a23a.jpg?imageView/0/w/100/h/100';
let {resource} = this.props;
let avator = resource?resource.get('avator'):'';
let username = resource?resource.get('username'):'';
let content = resource?resource.get('content'):'';
let isPraise = resource?resource.get('isPraise'):'N';
let praiseNum = resource?resource.get('praiseNum'):0;
let id = resource?resource.get('id'):0;
let create_time = resource?resource.get('create_time'):'';
let relayTo = resource?resource.get('relayTo'):null;
let relayToUsername = relayTo?relayTo.get('username'):'';
let thumbsUpIcon = isPraise=='Y' ? require('../../image/sc_icon.png') : require('../../image/wsc_icon.png');
return (
<View style={styles.container}>
<View style={styles.rightContainer}>
<YH_Image url={url} style={styles.icon}/>
<YH_Image url={avator} style={styles.icon}/>
</View>
<View style={styles.leftContainer}>
<View style={styles.headerContainer}>
<Text style={styles.name}>Andy</Text>
<TouchableOpacity onPress={()=>{this.props.onThumbsUp&&this.props.onThumbsUp('点赞')}}>
<Text style={styles.name}>{username}</Text>
<TouchableOpacity onPress={()=>{
this.props.onThumbsUp&&this.props.onThumbsUp(id,isPraise=='Y'?'N':'Y')
}}>
<View style={styles.thumbsUp}>
<Image style={styles.thumbsUpIcon} source={require('../../image/sc_icon.png')}/>
<Text style={styles.thumbsUpNum}>313</Text>
<Image style={styles.thumbsUpIcon} source={thumbsUpIcon}/>
<Text style={styles.thumbsUpNum}>{praiseNum}</Text>
</View>
</TouchableOpacity>
<Text style={styles.time}>4分钟前</Text>
<Text style={styles.time}>{create_time}</Text>
</View>
<View style={styles.commentView}>
<TouchableOpacity onPress={()=>{this.props.onComment&&this.props.onComment('评论')}}>
<Text style={styles.commentText}>店铺 样式修改的需求 是谁负责的 @自定义 我把他拉到讨论组里店铺 样式修改的需求 是谁负责的 @自定义 我把他拉到讨论组里店铺 样式修改的需求 是谁负责的 @自定义 我把他拉到讨论组里店铺 样式修改的需求 是谁负责的 @自定义 我把他拉到讨论组里</Text>
<TouchableOpacity onPress={()=>{this.props.onComment&&this.props.onComment(id)}}>
{relayTo ? <Text style={styles.commentText}>
回复
<Text style={styles.replayName}>{relayToUsername}</Text>
<Text style={styles.commentText}>{content}</Text>
</Text> : <Text style={styles.commentText}>{content}</Text>}
</TouchableOpacity>
</View>
<View style={styles.line}/>
... ... @@ -113,6 +132,7 @@ let styles = StyleSheet.create({
backgroundColor: 'white',
fontSize: 12,
color: 'gray',
width: 25,
},
time: {
position: 'absolute',
... ... @@ -131,6 +151,11 @@ let styles = StyleSheet.create({
textAlign: 'left',
backgroundColor: 'white',
fontSize: 15,
},
replayName: {
textAlign: 'left',
backgroundColor: 'white',
fontSize: 15,
fontWeight: 'bold',
},
line: {
... ...
... ... @@ -24,20 +24,33 @@ export default class CommentsTitle extends React.Component {
}
render() {
//let newSrc = getSlicedUrl(item.src, width, height, 2);
let url = 'http://head.static.yhbimg.com/yhb-head/2015/11/27/10/02497688cb0268347d08ce3df52af8a23a.jpg?imageView/0/w/100/h/100';
let {resource,total} = this.props;
let data = resource?resource.toJS():null;
let browseNum = data.browseNum?data.browseNum:0;
let id = data.id?data.id:0;
let isFavor = data.isFavor?data.isFavor:'N';
let isPraise = data.isPraise?data.isPraise:'N';
let praiseHeadIco = data.praiseHeadIco?data.praiseHeadIco:[];
let praiseNum = data.praiseNum?data.praiseNum:0;
let praiseText = praiseNum + '人点赞';
let browseNumText = browseNum + '人看过';
let title = '评论'+total;
let url1 = praiseHeadIco.length>0? praiseHeadIco[0]:'';
let url2 = praiseHeadIco.length>1? praiseHeadIco[1]:'';
let url3 = praiseHeadIco.length>2? praiseHeadIco[2]:'';
return (
<View style={styles.container}>
<View style={styles.contentContainer}>
<YH_Image url={url} style={styles.icon3}/>
<YH_Image url={url} style={styles.icon2}/>
<YH_Image url={url} style={styles.icon1}/>
<Text style={styles.rightText}>210人点赞</Text>
<Text style={styles.leftText}>9233人看过</Text>
<YH_Image url={url1} style={styles.icon3}/>
<YH_Image url={url2} style={styles.icon2}/>
<YH_Image url={url3} style={styles.icon1}/>
<Text style={styles.rightText}>{praiseText}</Text>
<Text style={styles.leftText}>{browseNumText}</Text>
</View>
<View style={{width: width,height: 1,backgroundColor: '#e5e5e5',}}/>
<View style={styles.commentTitle}>
<Text style={styles.commentTitleText}>评论2</Text>
<Text style={styles.commentTitleText}>{title}</Text>
</View>
</View>
);
... ...
... ... @@ -44,7 +44,6 @@ export default class Detail extends Component {
this.renderRow = this.renderRow.bind(this);
this.renderHeader = this.renderHeader.bind(this);
this.scrollTo = this.scrollTo.bind(this);
this._onThumbsUp = this._onThumbsUp.bind(this);
this._onComment = this._onComment.bind(this);
this._onSubmitEditing = this._onSubmitEditing.bind(this);
this.listView = null;
... ... @@ -54,6 +53,7 @@ export default class Detail extends Component {
});
this.state = {
viewMarginTop : new Animated.Value(0),
replyTo: 0,
};
}
... ... @@ -106,16 +106,20 @@ export default class Detail extends Component {
}
_onSubmitEditing(event){
console.log(event.nativeEvent.text);
this.refs.textInput.clear();
}
let content = event.nativeEvent.text;
let replyTos = this.state.replyTo;
_onThumbsUp(s){
console.log(s);
if (this.state.replyTo == 0) {
replyTos = '';
}
this.props.onSubmitForComment && this.props.onSubmitForComment(content,replyTos);
this.refs.textInput.clear();
this.setState({replyTo: 0});
}
_onComment(s){
console.log(s);
_onComment(id){
this.setState({replyTo: id});
this.refs.textInput && this.refs.textInput.focus();
}
renderHeader() {
... ... @@ -189,12 +193,15 @@ export default class Detail extends Component {
<WeChatPublic resource={rowData} onPressWeixin={this.props.onPressWeixin}/>
);
} else if (sectionID == 'commentsTitle'){
let {resource} = this.props;
let {commentsList} = resource;
let total = commentsList?commentsList.get('total'):0;
return (
<CommentsTitle resource={rowData} />
<CommentsTitle resource={rowData} total={total}/>
);
}else if (sectionID == 'comments'){
return (
<Comments resource={rowData} onThumbsUp={this._onThumbsUp} onComment={this._onComment}/>
<Comments resource={rowData} onThumbsUp={this.props.addPraiseForComments} onComment={this._onComment}/>
);
}else if (sectionID == 'space'){
return (
... ... @@ -217,22 +224,31 @@ export default class Detail extends Component {
weixin,
goods_group_Filter,
wechat,
commentsList,
addComment,
addPraiseInfo,
} = resource;
let list = content?content.get('data'):[];
let list = content?content.get('data'):null;
let comments = commentsList?commentsList.get('data'):null;
let dataSource = {
detailList: list.size?list.toArray():[],
detailList: list&&list.size>0?list.toArray():[],
weixin: [weixin],
detailBrand: [brand],
detailOtherArticle: [otherArticle],
tags:[article],
weChatPublic: [wechat],
commentsTitle: ['1'],
comments: ['1','2'],
commentsTitle: [addPraiseInfo],
comments: comments&&comments.size>0?comments.toArray():[],
space: ['1'],
};
let isFetching = content.isFetching || article.isFetching || author.isFetching;
let isFavor = addPraiseInfo.get('isFavor')?addPraiseInfo.get('isFavor'):'N';
let isPraise = addPraiseInfo.get('isPraise')?addPraiseInfo.get('isPraise'):'N';
let isFavorIcon = isFavor=='Y' ? require('../../image/sc_icon.png') : require('../../image/wsc_icon.png');
let isPraiseIcon = isPraise=='Y' ? require('../../image/sc_icon.png') : require('../../image/wsc_icon.png');
return (
<View style={styles.container}>
... ... @@ -258,11 +274,13 @@ export default class Detail extends Component {
onSubmitEditing = {this._onSubmitEditing}
clearButtonMode = 'while-editing'
ref = 'textInput'/>
<TouchableOpacity onPress={()=>{this.props.onPressConcerns&&this.props.onPressConcerns('关注')}}>
<Image style={styles.favIcon} source={require('../../image/sc_icon.png')}/>
<TouchableOpacity onPress={()=>{
this.props.onPressConcerns&&this.props.onPressConcerns(isFavor)}
}>
<Image style={styles.favIcon} source={isFavorIcon}/>
</TouchableOpacity>
<TouchableOpacity onPress={()=>{this._onThumbsUp&&this._onThumbsUp('点赞')}}>
<Image style={styles.thumbsUpIcon} source={require('../../image/sc_icon.png')}/>
<TouchableOpacity onPress={()=>{this.props.addPraiseForArtivle&&this.props.addPraiseForArtivle(isPraise)}}>
<Image style={styles.thumbsUpIcon} source={isPraiseIcon}/>
</TouchableOpacity>
</View>
</Animated.View>
... ...
... ... @@ -53,4 +53,43 @@ export default keyMirror({
GET_WECHAT_ATTEN_FAILURE: null,
LIKE_ARTICLE: null,
//获取资讯评论列表
GET_COMMENTS_LIST_REQUEST: null,
GET_COMMENTS_LIST_SUCCESS: null,
GET_COMMENTS_LIST_FAILURE: null,
//资讯添加评论
ADD_COMMENTS_FOR_ARTIVLE_REQUEST: null,
ADD_COMMENTS_FOR_ARTIVLE_SUCCESS: null,
ADD_COMMENTS_FOR_ARTIVLE_FAILURE: null,
//资讯内容点赞
ADD_PRAISE_FOR_COMMENTS_REQUEST: null,
ADD_PRAISE_FOR_COMMENTS_SUCCESS: null,
ADD_PRAISE_FOR_COMMENTS_FAILURE: null,
//文章点赞Info
GET_PRAISE_FOR_ARTIVLE_REQUEST: null,
GET_PRAISE_FOR_ARTIVLE_SUCCESS: null,
GET_PRAISE_FOR_ARTIVLE_FAILURE: null,
SET_PRAISE_FOR_COMMENTS: null,
//点赞文章
PRAISE_FOR_ARTIVLE_REQUEST: null,
PRAISE_FOR_ARTIVLE_SUCCESS: null,
PRAISE_FOR_ARTIVLE_FAILURE: null,
//取消点赞文章
CANCEL_PRAISE_FOR_ARTIVLE_REQUEST: null,
CANCEL_PRAISE_FOR_ARTIVLE_SUCCESS: null,
CANCEL_PRAISE_FOR_ARTIVLE_FAILURE: null,
//收藏
ADD_FAVORITE_REQUEST: null,
ADD_FAVORITE_SUCCESS: null,
ADD_FAVORITE_FAILURE: null,
//取消收藏
CANCEL_FAVORITE_REQUEST: null,
CANCEL_FAVORITE_SUCCESS: null,
CANCEL_FAVORITE_FAILURE: null,
});
... ...
... ... @@ -60,6 +60,10 @@ class DetailContainer extends Component {
this._onPressShopCar = this._onPressShopCar.bind(this);
this._onPressTagProduct = this._onPressTagProduct.bind(this);
this._onPressConcerns = this._onPressConcerns.bind(this);
this._onSubmitForComment = this._onSubmitForComment.bind(this);
this._addPraiseForArtivle = this._addPraiseForArtivle.bind(this);
this._addPraiseForComments = this._addPraiseForComments.bind(this);
}
componentDidMount() {
... ... @@ -68,14 +72,37 @@ class DetailContainer extends Component {
this.props.actions.getBrand();
this.props.actions.getWeixinPublic();
this.props.actions.getWeChatAtten();
this.props.actions.getCommentsList();
this.props.actions.getPraiseForArtivle();
}
componentWillUnmount() {
}
_onPressConcerns(e){
console.log(e);
_onSubmitForComment(content,replyTo){
this.props.actions.addCommentsForArtivle(content,replyTo);
}
_onPressConcerns(isFav){
if (isFav == 'N') {
this.props.actions.addFavorite();
}else {
this.props.actions.cancelFavorite();
}
}
_addPraiseForArtivle(isPraise){
if (isPraise == 'N') {
this.props.actions.praiseForArtivle();
}else {
this.props.actions.cancelPraiseForArtivle();
}
}
_addPraiseForComments(comment_id,praise){
this.props.actions.setPraiseForComments(comment_id,praise);
this.props.actions.addPraiseForComments(comment_id,praise);
}
_onPressFilter(value) {
... ... @@ -230,6 +257,9 @@ class DetailContainer extends Component {
onPressShopCar={this._onPressShopCar}
onPressTagProduct={this._onPressTagProduct}
onPressConcerns={this._onPressConcerns}
onSubmitForComment={this._onSubmitForComment}
addPraiseForArtivle={this._addPraiseForArtivle}
addPraiseForComments={this._addPraiseForComments}
/>
</View>
);
... ...
... ... @@ -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 => {
});
});
};
}
... ...
... ... @@ -43,6 +43,31 @@ let InitialState = Record({
})),
goods_group_Filter: 0,
goods_group_y: 0,
commentsList: new (Record({
isFetching: false,
error: null,
data: List(),
page: 1,
total: 0,
total_page: 0,
limit: 10,
})),
addComment: new (Record({
isFetching: false,
error: null,
data: List(),
message: '',
})),
addPraiseInfo: new (Record({
isFetching: false,
error: null,
browseNum: 0,
id: 0,
isFavor: 'N',
isPraise: 'N',
praiseHeadIco: List(),
praiseNum: 0,
})),
});
export default InitialState;
... ...
... ... @@ -39,6 +39,46 @@ 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;
const initialState = new InitialState;
... ... @@ -175,6 +215,97 @@ export default function detailReducer(state=initialState, action) {
case SET_GOOESGROUP_Y: {
return state.set('goods_group_y', action.payload);
}
//获取资讯评论列表
case GET_COMMENTS_LIST_REQUEST: {
return state.setIn(['commentsList', 'isFetching'], true)
.setIn(['commentsList', 'error'], null);
}
case GET_COMMENTS_LIST_SUCCESS: {
return state.setIn(['commentsList', 'isFetching'], false)
.setIn(['commentsList', 'error'], null)
.setIn(['commentsList', 'page'], action.payload.page)
.setIn(['commentsList', 'total'], action.payload.total)
.setIn(['commentsList', 'total_page'], action.payload.total_page)
.setIn(['commentsList', 'data'], Immutable.fromJS(action.payload.data));
}
case GET_COMMENTS_LIST_FAILURE: {
return state.setIn(['commentsList', 'isFetching'], false)
.setIn(['commentsList', 'error'], action.payload);
}
//资讯添加评论
case ADD_COMMENTS_FOR_ARTIVLE_REQUEST: {
return state.setIn(['addComment', 'isFetching'], true)
.setIn(['addComment', 'message'], '')
.setIn(['addComment', 'error'], null);
}
case ADD_COMMENTS_FOR_ARTIVLE_SUCCESS: {
return state.setIn(['addComment', 'isFetching'], false)
.setIn(['addComment', 'error'], null)
.setIn(['addComment', 'data'], Immutable.fromJS(action.payload)
.setIn(['addComment', 'message'], '发表评论成功'));
}
case ADD_COMMENTS_FOR_ARTIVLE_FAILURE: {
return state.setIn(['addComment', 'isFetching'], false)
.setIn(['addComment', 'message'], '发表评论失败')
.setIn(['addComment', 'error'], action.payload);
}
case SET_PRAISE_FOR_COMMENTS: {
return state.setIn(['commentsList', 'data'], Immutable.fromJS(action.payload));
}
//资讯内容点赞
case ADD_PRAISE_FOR_COMMENTS_REQUEST: {
break;
}
case ADD_PRAISE_FOR_COMMENTS_SUCCESS: {
break;
}
case ADD_PRAISE_FOR_COMMENTS_FAILURE: {
break;
}
//文章点赞Info
case GET_PRAISE_FOR_ARTIVLE_REQUEST: {
return state.setIn(['addPraiseInfo', 'isFetching'], true)
.setIn(['addPraiseInfo', 'error'], null);
}
case GET_PRAISE_FOR_ARTIVLE_SUCCESS: {
return state.setIn(['addPraiseInfo', 'isFetching'], false)
.setIn(['addPraiseInfo', 'browseNum'], action.payload.browseNum)
.setIn(['addPraiseInfo', 'id'], action.payload.id)
.setIn(['addPraiseInfo', 'isFavor'], action.payload.isFavor)
.setIn(['addPraiseInfo', 'isPraise'], action.payload.isPraise)
.setIn(['addPraiseInfo', 'praiseHeadIco'], Immutable.fromJS(action.payload.praiseHeadIco))
.setIn(['addPraiseInfo', 'praiseNum'], action.payload.praiseNum)
.setIn(['addPraiseInfo', 'error'], null);
}
case GET_PRAISE_FOR_ARTIVLE_FAILURE: {
return state.setIn(['addPraiseInfo', 'isFetching'], false)
.setIn(['addPraiseInfo', 'error'], action.payload);
}
case PRAISE_FOR_ARTIVLE_REQUEST:
{
return state.setIn(['addPraiseInfo', 'isPraise'], 'Y');
}
case PRAISE_FOR_ARTIVLE_SUCCESS:{break;}
case PRAISE_FOR_ARTIVLE_FAILURE:{break;}
case CANCEL_PRAISE_FOR_ARTIVLE_REQUEST:
{
return state.setIn(['addPraiseInfo', 'isPraise'], 'N');
}
case CANCEL_PRAISE_FOR_ARTIVLE_SUCCESS:{break;}
case CANCEL_PRAISE_FOR_ARTIVLE_FAILURE:{break;}
case ADD_FAVORITE_REQUEST:
{
return state.setIn(['addPraiseInfo', 'isFavor'], 'Y');
}
case ADD_FAVORITE_SUCCESS:{break;}
case ADD_FAVORITE_FAILURE:{break;}
case CANCEL_FAVORITE_REQUEST:
{
return state.setIn(['addPraiseInfo', 'isFavor'], 'N');
}
case CANCEL_FAVORITE_SUCCESS:{break;}
case CANCEL_FAVORITE_FAILURE:{break;}
}
return state;
... ...
... ... @@ -145,4 +145,139 @@ export default class DetailService {
throw(error);
});
}
async getCommentsList(article_id, page=1, limit=10) {
return await this.api.get({
url: '/guang/api/v1/comments/getList',
body: {
article_id,
page,
limit,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
async addCommentsForArtivle(article_id, uid, content='', replyTo) {
return await this.api.get({
url: '/guang/api/v1/comments/add',
body: {
article_id,
content,
replyTo,
uid,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
async addPraiseForComments(comment_id, praise, article_id) {
return await this.api.get({
url: '/guang/api/v2/comments/praise',
body: {
comment_id,
praise,
article_id,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
//文章点赞info 用户uid 文章id
async getPraiseForArtivle(uid, id) {
return await this.api.get({
url: '/guang/api/v2/article/getArticlePraiseAndFavor',
body: {
uid,
id,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
//点赞文章
async praiseForArtivle(article_id) {
return await this.api.get({
url: '/guang/api/v2/praise/setPraise',
body: {
article_id,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
//取消点赞文章
async cancelPraiseForArtivle(article_id) {
return await this.api.get({
url: '/guang/api/v2/praise/cancel',
body: {
article_id,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
//收藏文章
async addFavorite(uid, article_id) {
return await this.api.get({
url: '/guang/api/v1/favorite/setFavorite',
body: {
uid,
article_id,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
//取消收藏文章
async cancelFavorite(uid, article_id) {
return await this.api.get({
url: '/guang/api/v1/favorite/cancelFavorite',
body: {
uid,
article_id,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
}
... ...