Authored by 盖剑秋

Fix share bug. reviewed by redding .

... ... @@ -36,7 +36,6 @@ export default class SPLikeCell extends React.Component {
_renderLikeAvatar(avatars) {
let users = this.props.users;
if (users.length) {
users.reverse();
let space = 10;
let left = (users.length - 1) * space;
return (
... ...
... ... @@ -379,9 +379,9 @@ export default class SubjectPost extends Component {
return (
<TouchableOpacity onPress={this.props.onPressShareGoods}>
<View style={styles.shareGoodsContainer}>
<SlicedImage style={styles.shareGoodsImage} source={{uri:rowData.productUrl}}/>
<SlicedImage style={styles.shareGoodsImage} source={{uri:rowData.goodsImage}}/>
<View style={styles.shareGoodsRightPannel}>
<Text style={styles.productNameText}>rowData.productName</Text>
<Text style={styles.productNameText}>{rowData.productName}</Text>
<Text style={styles.productPriceText}>{'¥'+rowData.salesPrice}</Text>
</View>
</View>
... ...
... ... @@ -132,6 +132,7 @@ export default keyMirror({
SUBJECT_DEL_COMMENT_REQUEST: null,
SUBJECT_DEL_COMMENT_SUCCESS: null,
SUBJECT_DEL_COMMENT_FAILURE: null,
SUBJECT_SHARE_DATA_PREPARED: null,
LIKE_MESSAGE_REQUEST: null, // 消息中心收到的赞列表
LIKE_MESSAGE_SUCCESS: null,
... ...
... ... @@ -94,6 +94,7 @@ class SubjectPostContainer extends Component {
InteractionManager.runAfterInteractions(() => {
this.props.actions.requestPostContent(this.sid,item.id);
this.props.actions.requestPostComments(this.sid,item.id);
this.props.actions.prepareShareData(this.sid,item.id);
});
}
... ... @@ -146,7 +147,7 @@ class SubjectPostContainer extends Component {
onPressShareGoods() {
let item = this.props.subject.items.get(this.sid);
let params = {
productSkn: item.shareProductSkn,
productSkn: item.shareGoods.productId,
};
NativeModules.YH_CommunityHelper.displayProductDetail(params);
}
... ...
... ... @@ -39,6 +39,7 @@ const {
SUBJECT_DEL_COMMENT_REQUEST,
SUBJECT_DEL_COMMENT_SUCCESS,
SUBJECT_DEL_COMMENT_FAILURE,
SUBJECT_SHARE_DATA_PREPARED,
} = require('../../constants/actionTypes').default;
export function deleteComment(sid, id) {
... ... @@ -79,8 +80,8 @@ export function subjectLikeRequest(sid,json) {
export function subjectLike(sid,postId) {
return (dispatch, getState) => {
dispatch(subjectLikeRequest(sid,postId));
let {user} = getState();
dispatch(subjectLikeRequest(sid,user.profile.avatar));
return new HomeService().postLike(postId, user.profile.uid)
.then(json => {
dispatch({
... ... @@ -103,8 +104,8 @@ export function subjectUnlikeRequest(sid,json) {
export function subjectUnlike(sid,postId) {
return (dispatch, getState) => {
dispatch(subjectUnlikeRequest(sid,postId));
let {user} = getState();
dispatch(subjectUnlikeRequest(sid,user.profile.avatar));
return new HomeService().postUnlike(postId, user.profile.uid)
.then(json => {
dispatch({
... ... @@ -137,18 +138,16 @@ export function onRightPressed(sid) {
}
});
} else {
let params = {
postsId: item.id,
appType: 1,
}
new PostingService().getShareUrl(params).then(json => {
let {subject} = getState();
let item = subject.items.get(sid);
let {subject} = getState();
let item = subject.items.get(sid);
console.log('aaaaaaaaaaaaaa');
console.log(item.shareUrl);
if (item.shareUrl.length) {
let blockAry = item.blocks.toJS();
let content = '';
let contentStr = '';
for (var i = 0; i < blockAry.length; i++) {
if (blockAry[i].templateKey == 'text') {
content = blockAry[i].contentData||'';
contentStr = blockAry[i].contentData||'';
break;
}
}
... ... @@ -159,6 +158,7 @@ export function onRightPressed(sid) {
break;
}
}
console.log('bbbbbbbbbbbbbb');
let newSrc = picUrl;
if (picUrl.length) {
if (picUrl.indexOf('imageView') === -1) {
... ... @@ -169,21 +169,46 @@ export function onRightPressed(sid) {
.replace('{height}', '320');
}
}
console.log('cccccccccccccccc');
let title = item.postsTitle||contentStr||'潮流社区';
let content = item.authorInfo.nickName||''+'在潮流社区发布的潮流主题帖很赞,快来看看!'
let shareInfo = {
title: subject.postsTitle||'',
title,
content,
'picUrl':newSrc,
linkUrl: json.shareUrl,
picUrl:newSrc,
linkUrl: item.shareUrl,
}
console.log('ddddddddddddd');
dispatch(doShare(sid,shareInfo));
}).catch(error => {
console.log('ddddddddddddddddd');
} else {
Alert.alert('提示','获取分享信息失败');
})
}
}
}
}
export function prepareShareData(sid, postId) {
return dispatch => {
let params = {
postsId: postId,
appType: 1,
};
new PostingService().getShareUrl(params).then(json => {
dispatch(shareDataPrepared(sid, json.shareUrl));
}).catch(error => {
});
}
}
export function shareDataPrepared(sid, shareUrl) {
return {
type: SUBJECT_SHARE_DATA_PREPARED,
payload: {sid, shareUrl},
}
}
export function onRight(sid) {
return {
type:'SUBJECT_DO_NOTHING',
... ... @@ -193,7 +218,7 @@ export function onRight(sid) {
export function doShare(sid,shareInfo) {
NativeModules.YH_CommunityHelper.showShare(shareInfo);
console.log('ffffffffffff');
return {
type:'SUBJECT_DO_NOTHING',
payload: sid,
... ... @@ -436,6 +461,7 @@ export function commitComment(sid,params, newList) {
new PostingService().commitReply(params)
.then(response => {
Alert.alert('提示','回复成功');
newList[0].commentId = response.id;
dispatch(commentSuccess(sid,response, newList));
}).catch(error => {
Alert.alert('提示','回复失败');
... ...
... ... @@ -40,6 +40,7 @@ let item = new (Record({
productUrl: '',
salesPrice: 0,
goodsImage: '',
productId:'',
})),
publishTimeString: '',
shareProductSkn: 0,
... ... @@ -58,6 +59,7 @@ let item = new (Record({
inLikeAction: false,
largeImages:[],
shareUrl: '',
}));
let InitialState = Record({
... ...
... ... @@ -39,6 +39,8 @@ const {
SUBJECT_DEL_COMMENT_REQUEST,
SUBJECT_DEL_COMMENT_SUCCESS,
SUBJECT_DEL_COMMENT_FAILURE,
SUBJECT_SHARE_DATA_PREPARED,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
... ... @@ -125,10 +127,16 @@ export default function postingReducer(state = initialState, action) {
.set('largeImages',largeImages)
.set('hasPraise',hasPraise||'N');
if (shareGoods) {
item.setIn(['shareGoods','productName'],shareGoods.productName||'')
let imgUrl = '';
if (shareGoods.goodsImage.length) {
let ary=shareGoods.goodsImage.split('?');
imgUrl = ary[0];
}
item = item.setIn(['shareGoods','productName'],shareGoods.productName||'')
.setIn(['shareGoods','productUrl'],shareGoods.productUrl||'')
.setIn(['shareGoods','salesPrice'],shareGoods.salesPrice||'')
.setIn(['shareGoods','goodsImage'],shareGoods.goodsImage||'')
.setIn(['shareGoods','goodsImage'],imgUrl||'')
.setIn(['shareGoods','productId'],shareGoods.productId)
}
let nextState = state.setIn(['items', sid], item);
return nextState;
... ... @@ -229,7 +237,9 @@ export default function postingReducer(state = initialState, action) {
case SUBJECT_LIKE_REQUEST: {
let {sid,json} = action.payload;
let item = state.items.get(sid);
item = item.set('hasPraise','Y');
let users = item.praiseUsers.toJS();
let newUsers = [{headIcon:json},...users];
item = item.set('hasPraise','Y').set('praiseUsers',Immutable.fromJS(newUsers));
let nextState = state.setIn(['items', sid], item);
return nextState;
}
... ... @@ -237,7 +247,15 @@ export default function postingReducer(state = initialState, action) {
case SUBJECT_UNLIKE_REQUEST: {
let {sid,json} = action.payload;
let item = state.items.get(sid);
item = item.set('hasPraise','N');
let users = item.praiseUsers.toJS();
let newUsers = [];
for (var i = 0; i < users.length; i++) {
let item = users[i];
if (item.headIcon != json) {
newUsers.push(item);
}
}
item = item.set('hasPraise','N').set('praiseUsers',Immutable.fromJS(newUsers));
let nextState = state.setIn(['items', sid], item);
return nextState;
}
... ... @@ -250,6 +268,14 @@ export default function postingReducer(state = initialState, action) {
return nextState;
}
break;
case SUBJECT_SHARE_DATA_PREPARED: {
let {sid, shareUrl} = action.payload;
let item = state.items.get(sid);
item = item.set('shareUrl',shareUrl);
let nextState = state.setIn(['items', sid], item);
return nextState;
}
break;
case SUBJECT_DO_NOTHING:
return state;
break;
... ...