Authored by 盖剑秋

Add sid to subject post initial state. reviewed by redding.

... ... @@ -29,12 +29,12 @@ export default class SubjectContent extends Component {
<Text key={i} style={styles.contentText}>
<Text>回复</Text>
<Text style={{color:'#4a90e2'}} onPress={()=>{this.props.onPressAvatar(this.props.replyTo.uid);}}>{this.props.replyTo.nickName}</Text>
<Text>':'+{decodeURI(content)}</Text>
<Text>':'+{content}</Text>
</Text>
)
}else {
return(
<Text key={i} style={styles.contentText}>{decodeURI(content)}</Text>
<Text key={i} style={styles.contentText}>{content}</Text>
)
}
... ...
... ... @@ -302,7 +302,7 @@ export default class SubjectPost extends Component {
cidFrom: this.props.cidFrom,
cidTo: this.cidTo,
authorUid: this.props.authorUid,
content: encodeURI(this.replyContent),
content: this.replyContent,
}
this.props.commentWithParams(params);
this.blurAll();
... ...
... ... @@ -67,12 +67,14 @@ class SubjectPostContainer extends Component {
this.onPressLikeOrDislike = this.onPressLikeOrDislike.bind(this);
this.onPressShareGoods = this.onPressShareGoods.bind(this);
this.onPressLargeImage = this.onPressLargeImage.bind(this);
this.sid = this.props.subject.sid;
}
componentDidMount() {
let item = this.props.subject.items.get(this.sid);
InteractionManager.runAfterInteractions(() => {
this.props.actions.requestPostContent(this.props.postId);
this.props.actions.requestPostComments(this.props.postId);
this.props.actions.requestPostContent(this.sid,item.id);
this.props.actions.requestPostComments(this.sid,item.id);
});
}
... ... @@ -81,10 +83,11 @@ class SubjectPostContainer extends Component {
}
onEndReached() {
if (this.props.subject.currentPage>=this.props.subject.totalPages) {
let item = this.props.subject.items.get(this.sid);
if (item.currentPage>=item.totalPages) {
return;
}
this.props.actions.requestPostComments(300, this.props.subject.lastedTime);
this.props.actions.requestPostComments(this.sid, item.id, item.lastedTime);
}
onPressLargeImage(index) {
... ... @@ -92,16 +95,17 @@ class SubjectPostContainer extends Component {
}
assetsSelected(assets) {
this.props.actions.assetsSelected(assets);
this.props.actions.assetsSelected(this.sid,assets);
}
commentWithParams(params) {
this.props.actions.commentWithParams(params);
this.props.actions.commentWithParams(this.sid,params);
}
onPressShareGoods() {
let item = this.props.subject.items.get(this.sid);
let params = {
productSkn: this.props.subject.shareProductSkn,
productSkn: item.shareProductSkn,
};
NativeModules.YH_CommunityHelper.displayProductDetail(params);
}
... ... @@ -114,26 +118,28 @@ class SubjectPostContainer extends Component {
}
onPressReportOrDelete() {
if (this.props.subject.LZ) {
this.props.actions.doDelete(this.props.subject.id);
let item = this.props.subject.items.get(this.sid);
if (item.LZ) {
this.props.actions.doDelete(this.sid,item.id);
} else {
let params = {
postsId: this.props.subject.id,
postsId: item.id,
loginUid: this.props.user.profile.uid,
contentData: '涉黄',
}
this.props.actions.doReport(params);
this.props.actions.doReport(this.sid,params);
}
}
onPressLikeOrDislike() {
if (this.props.subject.inLikeAction) {
let item = this.props.subject.items.get(this.sid);
if (item.inLikeAction) {
return;
}
if (this.props.subject.hasPraise == 'Y') {
this.props.actions.subjectUnlike(this.props.subject.id);
if (item.hasPraise == 'Y') {
this.props.actions.subjectUnlike(this.sid,item.id);
}else if(this.props.subject.hasPraise == 'N'){
this.props.actions.subjectLike(this.props.subject.id);
this.props.actions.subjectLike(this.sid,item.id);
}
}
... ... @@ -142,34 +148,35 @@ class SubjectPostContainer extends Component {
}
render() {
let {headIcon,nickName,uid} = this.props.subject.authorInfo;
let timeagoStr = timeago().format(this.props.subject.createTime, 'zh_CN');
let item = this.props.subject.items.get(this.sid);
let {headIcon,nickName,uid} = item.authorInfo;
let timeagoStr = timeago().format(item.createTime, 'zh_CN');
let header = {
uid,
headIcon,
nickName,
forumCode: this.props.subject.forumCode,
forumName: this.props.subject.forumName,
forumCode: item.forumCode,
forumName: item.forumName,
timeago: timeagoStr,
LZ: this.props.subject.LZ,
LZ: item.LZ,
}
let likeData = {
praiseUsers: this.props.subject.praiseUsers.toJS(),
praise: this.props.subject.praise,
browse: this.props.subject.browse,
postId: this.props.subject.id,
praiseUsers: item.praiseUsers.toJS(),
praise: item.praise,
browse: item.browse,
postId: item.id,
}
let shareGoods = [];
if (this.props.subject.shareGoods.productName.length) {
shareGoods.push(this.props.subject.shareGoods);
if (item.shareGoods.productName.length) {
shareGoods.push(item.shareGoods);
}
let dataBlob = {
header : [header],
title: [this.props.subject.postsTitle],
content: [this.props.subject.blocks.toJS()],
title: [item.postsTitle],
content: [item.blocks.toJS()],
shareGoods,
like: [likeData],
comments: this.props.subject.commentList.toJS(),
comments: item.commentList.toJS(),
};
return (
... ... @@ -177,21 +184,21 @@ class SubjectPostContainer extends Component {
<SubjectPost
dataBlob={dataBlob}
onEndReached={this.onEndReached}
endReached={this.props.subject.currentPage>=this.props.subject.totalPages}
isFetching={this.props.subject.isCommentsFetching}
endReached={item.currentPage>=item.totalPages}
isFetching={item.isCommentsFetching}
assetsSelected={this.assetsSelected}
assets={this.props.subject.assets.toJS()}
commentCount={this.props.subject.commentCount}
assets={item.assets.toJS()}
commentCount={item.commentCount}
commentWithParams={this.commentWithParams}
postId={this.props.subject.id}
postId={item.id}
cidFrom={this.props.user.profile.uid}
authorUid={this.props.subject.authorInfo.uid}
authorUid={item.authorInfo.uid}
onPressAvatar={this.onPressAvatar}
onPressSection={this.onPressSection}
onPressReportOrDelete={this.onPressReportOrDelete}
onPressLikeCell={this.onPressLikeCell}
onPressLikeOrDislike={this.onPressLikeOrDislike}
likeState={this.props.subject.hasPraise}
likeState={item.hasPraise}
onPressShareGoods={this.onPressShareGoods}
onPressLargeImage={this.onPressLargeImage}
/>
... ...
... ... @@ -319,17 +319,17 @@ function parseBNS(json) {
},
hot: {
avatar: hotAvatar,
content: hotPost && hotPost.contentData ? decodeURI(hotPost.contentData) : '',
content: hotPost && hotPost.contentData ? hotPost.contentData : '',
hasImg: hotPost && hotPost.hasImgFlg ? hotPost.hasImgFlg : '',
postId: hotPost && hotPost.postId ? hotPost.postId : '',
postTitle: hotPost && hotPost.postsTitle ? decodeURI(hotPost.postsTitle) : '',
postTitle: hotPost && hotPost.postsTitle ? hotPost.postsTitle : '',
},
new: {
avatar: newAvatar,
content: newPost && newPost.contentData ? decodeURI(newPost.contentData) : '',
content: newPost && newPost.contentData ? newPost.contentData : '',
hasImg: newPost && newPost.hasImgFlg ? newPost.hasImgFlg : '',
postId: newPost && newPost.postId ? newPost.postId : '',
postTitle: newPost && newPost.postsTitle ? decodeURI(newPost.postsTitle) : '',
postTitle: newPost && newPost.postsTitle ? newPost.postsTitle : '',
},
num: {
onedayAddNum: item.oneDayAddNum,
... ... @@ -363,7 +363,7 @@ function parseRecommendation(json) {
blocks && blocks.map((item, i) => {
let contentData = item.contentData ? item.contentData : '';
if (desc === '' && item.templateKey === 'text') {
desc = decodeURI(contentData);
desc = contentData;
}
if (item.templateKey === 'image') {
... ... @@ -380,7 +380,7 @@ function parseRecommendation(json) {
let createTime = item.createTime;
let timeagoStr = timeago(createTime);
let isLike = item.hasPraise === 'Y' ? true : false;
let title = item.postsTitle ? decodeURI(item.postsTitle) : '';
let title = item.postsTitle ? item.postsTitle : '';
if (title === '') {
title = desc;
desc = '';
... ...
... ... @@ -192,10 +192,10 @@ export function updateUploadState(url,fileName) {
sizeStr += assets[i].width + 'x' + assets[i].height +',';
}
let param = {
postsTitle: encodeURI(posting.title),
postsTitle: posting.title,
uid: ssouid,
forumCode: posting.currentBoardId,
contentData: encodeURI(posting.content),
contentData: posting.content,
images: imageStr,
sizes: sizeStr,
}
... ...
... ... @@ -291,7 +291,7 @@ function parseNewPost(json) {
blocks && blocks.map((item, i) => {
let contentData = item.contentData ? item.contentData : '';
if (desc === '' && item.templateKey === 'text') {
desc = decodeURI(contentData);
desc = contentData;
}
if (item.templateKey === 'image') {
... ... @@ -308,7 +308,7 @@ function parseNewPost(json) {
let createTime = item.createTime;
let timeagoStr = timeago(createTime);
let isLike = item.hasPraise === 'Y' ? true : false;
let title = item.postsTitle ? decodeURI(item.postsTitle) : '';
let title = item.postsTitle ? item.postsTitle : '';
if (title === '') {
title = desc;
desc = '';
... ...
... ... @@ -46,16 +46,16 @@ export function goToLikeList(postId, likeCount) {
};
}
export function subjectLikeRequest(json) {
export function subjectLikeRequest(sid,json) {
return {
type: SUBJECT_LIKE_REQUEST,
payload: json
payload: {sid,json}
};
}
export function subjectLike(postId) {
export function subjectLike(sid,postId) {
return (dispatch, getState) => {
dispatch(subjectLikeRequest(postId));
dispatch(subjectLikeRequest(sid,postId));
let {user} = getState();
return new HomeService().postLike(postId, user.profile.uid)
.then(json => {
... ... @@ -70,16 +70,16 @@ export function subjectLike(postId) {
};
}
export function subjectUnlikeRequest(json) {
export function subjectUnlikeRequest(sid,json) {
return {
type: SUBJECT_UNLIKE_REQUEST,
payload: json
payload: {sid,json}
};
}
export function subjectUnlike(postId) {
export function subjectUnlike(sid,postId) {
return (dispatch, getState) => {
dispatch(subjectUnlikeRequest(postId));
dispatch(subjectUnlikeRequest(sid,postId));
let {user} = getState();
return new HomeService().postUnlike(postId, user.profile.uid)
.then(json => {
... ... @@ -95,11 +95,12 @@ export function subjectUnlike(postId) {
}
export function onRightPressed() {
export function onRightPressed(sid) {
return (dispatch, getState) => {
dispatch(onRight());
dispatch(onRight(sid));
let {subject} = getState();
if (subject.LZ && !subject.revieweState) {
let item = subject.items.get(sid);
if (item.LZ && !item.revieweState) {
const BUTTONS = ['删除','取消'];
ActionSheetIOS.showActionSheetWithOptions({
options: BUTTONS,
... ... @@ -108,17 +109,18 @@ export function onRightPressed() {
(buttonIndex) => {
if (buttonIndex == 0) {
dispatch(doDelete(subject.id));
dispatch(doDelete(sid,item.id));
}
});
} else {
let params = {
postsId: subject.id,
postsId: item.id,
appType: 1,
}
new PostingService().getShareUrl(params).then(json => {
let {subject} = getState();
let blockAry = subject.blocks.toJS();
let item = subject.items.get(sid);
let blockAry = item.blocks.toJS();
let content = '';
for (var i = 0; i < blockAry.length; i++) {
if (blockAry[i].templateKey == 'text') {
... ... @@ -149,10 +151,8 @@ export function onRightPressed() {
'picUrl':newSrc,
linkUrl: json.shareUrl,
}
console.log(shareInfo);
dispatch(doShare(shareInfo));
dispatch(doShare(sid,shareInfo));
}).catch(error => {
console.log(error);
Alert.alert('提示','获取分享信息失败');
})
... ... @@ -160,23 +160,25 @@ export function onRightPressed() {
}
}
export function onRight() {
export function onRight(sid) {
return {
type:'SUBJECT_DO_NOTHING'
type:'SUBJECT_DO_NOTHING',
payload:sid,
}
}
export function doShare(shareInfo) {
export function doShare(sid,shareInfo) {
console.log(shareInfo);
NativeModules.YH_CommunityHelper.showShare(shareInfo);
return {
type:'SUBJECT_DO_NOTHING'
type:'SUBJECT_DO_NOTHING',
payload: sid,
}
}
export function doDelete(postsId) {
export function doDelete(sid,postsId) {
Alert.alert('提示','是否确认删除?',
[{text:'否'},
... ... @@ -192,11 +194,12 @@ export function doDelete(postsId) {
}}]);
console.log('deleted.............');
return {
type:'SUBJECT_DO_NOTHING'
type:'SUBJECT_DO_NOTHING',
payload:sid,
}
}
export function doReport(params) {
export function doReport(sid, params) {
new PostingService().reportPost(params).then(json => {
Alert.alert('提示','举报成功');
}).catch(error => {
... ... @@ -204,92 +207,100 @@ export function doReport(params) {
});
return {
type:'SUBJECT_DO_NOTHING'
type:'SUBJECT_DO_NOTHING',
payload:sid,
}
}
export function requestPostContent(postsId) {
export function contentSuccess(sid,json) {
return dispatch => {
dispatch(doRequestContent());
let rightImg = require('../../images/posting/share.png');
if (json.LZ&&!json.revieweState) {
rightImg = require('../../images/posting/more.png');
}
Actions.refresh({key: 'SubjectPost', rightButtonImage:rightImg});
let largeImages = [];
let index=0;
for (var i = 0; i < json.blocks.length; i++) {
let item = json.blocks[i];
if (item.templateKey == 'image') {
let urlStr = item.contentData||'';
let imgWidth = 640;
let imgHeight = imgWidth;
let sizeStr = item.size || '';
if (sizeStr.length) {
let ary=sizeStr.split('x');
let w = parseInt(ary[0]);
let h = parseInt(ary[1]);
if (w&&h) {
imgHeight = imgWidth/w*h;
}
}
let newSrc = urlStr;
if (urlStr.indexOf('imageView') === -1) {
newSrc = urlStr + '?imageView2/' + '1' + '/w/' + imgWidth + '/h/' + imgHeight;
} else {
newSrc = urlStr.replace('{mode}', '1')
.replace('{width}', imgWidth)
.replace('{height}', imgHeight);
}
largeImages.push(newSrc);
json.blocks[i].index=index;
index++;
}
}
json.largeImages = largeImages;
dispatch(contentRequestSuccess(sid,json));
}
}
export function requestPostContent(sid,postsId) {
return dispatch => {
dispatch(doRequestContent(sid));
let params = {postsId};
new PostingService().getPostContent(params)
.then(json => {
NativeModules.YH_CommunityHelper.uid()
.then(uid => {
json.LZ = (uid == json.authorInfo.uid);
let rightImg = require('../../images/posting/share.png');
if (json.LZ&&!json.revieweState) {
rightImg = require('../../images/posting/more.png');
}
Actions.refresh({key: 'SubjectPost', rightButtonImage:rightImg});
let largeImages = [];
let index=0;
for (var i = 0; i < json.blocks.length; i++) {
let item = json.blocks[i];
if (item.templateKey == 'image') {
let urlStr = item.contentData||'';
let imgWidth = 640;
let imgHeight = imgWidth;
let sizeStr = item.size || '';
if (sizeStr.length) {
let ary=sizeStr.split('x');
let w = parseInt(ary[0]);
let h = parseInt(ary[1]);
if (w&&h) {
imgHeight = imgWidth/w*h;
}
}
let newSrc = urlStr;
if (urlStr.indexOf('imageView') === -1) {
newSrc = urlStr + '?imageView2/' + '1' + '/w/' + imgWidth + '/h/' + imgHeight;
} else {
newSrc = urlStr.replace('{mode}', '1')
.replace('{width}', imgWidth)
.replace('{height}', imgHeight);
}
largeImages.push(newSrc);
json.blocks[i].index=index;
index++;
}
}
json.largeImages = largeImages;
dispatch(contentRequestSuccess(json));
dispatch(contentSuccess(sid,json));
})
.catch(error => {
json.LZ = false;
dispatch(contentRequestSuccess(json));
dispatch(contentSuccess(sid,json));
});
})
.catch(error => {
dispatch(contentRequestFailure(error));
dispatch(contentRequestFailure(sid,error));
});
}
}
export function doRequestContent() {
export function doRequestContent(sid) {
return {
type: SUBJECT_CONTENT_REQUEST,
payload: sid,
}
}
export function contentRequestSuccess(json) {
export function contentRequestSuccess(sid,json) {
return {
type: SUBJECT_CONTENT_SUCCESS,
payload: json,
payload: {sid,json},
}
}
export function contentRequestFailure(error) {
export function contentRequestFailure(sid,error) {
return {
type: SUBJECT_CONTENT_FAILURE,
payload: error,
payload: {sid,error},
}
}
export function requestPostComments(postsId, lastedTime) {
export function requestPostComments(sid, postsId, lastedTime) {
return dispatch => {
dispatch(doRequestComments());
dispatch(doRequestComments(sid));
let params = {
postsId,
lastedTime,
... ... @@ -297,22 +308,23 @@ export function requestPostComments(postsId, lastedTime) {
};
new PostingService().getPostComments(params)
.then(json => {
dispatch(commentsRequestSuccess(json));
dispatch(commentsRequestSuccess(sid,json));
})
.catch(error => {
dispatch(commentsRequestFailure(error));
dispatch(commentsRequestFailure(sid,error));
});
}
}
export function doRequestComments() {
export function doRequestComments(sid) {
return {
type: SUBJECT_COMMENTS_REQUEST,
payload: sid,
}
}
export function commentsRequestSuccess(json) {
export function commentsRequestSuccess(sid,json) {
let {list} = json;
let newList = [];
list && list.map((obj,i)=> {
... ... @@ -348,82 +360,87 @@ export function commentsRequestSuccess(json) {
json.list = newList;
return {
type: SUBJECT_COMMENTS_SUCCESS,
payload: json,
payload: {sid,json},
}
}
export function commentsRequestFailure(error) {
export function commentsRequestFailure(sid,error) {
return {
type: SUBJECT_COMMENTS_FAILURE,
payload: error,
payload: {sid,error},
}
}
export function assetsSelected(assets) {
export function assetsSelected(sid,assets) {
return {
type: SUBJECT_ASSETS_SELECTED,
payload: assets,
payload: {sid,assets},
}
}
export function commentWithParams(params) {
export function commentWithParams(sid,params) {
return (dispatch, getState) => {
dispatch(startComment());
dispatch(startComment(sid));
let {subject} = getState();
let assets = subject.assets.toJS();
let item = subject.items.get(sid);
let assets = item.assets.toJS();
if (assets.length) {
for (let i = 0; i < assets.length; i++) {
let asset = assets[i]
new PostingService().uploadImageAsset(asset)
.then(response => {
dispatch(updateCommentProgress(response, params));
dispatch(updateCommentProgress(sid,response, params));
}).catch(error => {
dispatch(commentFail(error));
dispatch(commentFail(sid,error));
});
}
} else {
dispatch(commitComment(params));
dispatch(commitComment(sid,params));
}
}
}
export function startComment() {
export function startComment(sid) {
return {
type: SUBJECT_REPLY_REQUEST,
payload: sid,
}
}
export function commitComment(params) {
export function commitComment(sid,params) {
return dispatch => {
new PostingService().commitReply(params)
.then(response => {
dispatch(commentSuccess(response));
dispatch(commentSuccess(sid,response));
}).catch(error => {
dispatch(commentFail(error));
dispatch(commentFail(sid,error));
});
}
}
export function updateCommentProgress(url, params) {
export function updateCommentProgress(sid, url, params) {
return (dispatch, getState) => {
let {subject} = getState();
let {assetsUrlStr, assetFinishCount} = subject;
let item = subject.items.get(sid);
let {assetsUrlStr, assetFinishCount} = item;
let newStr = assetsUrlStr + url + ',';
let newCount = assetFinishCount + 1;
let payloadData = {
sid,
newStr,
newCount,
};
dispatch(commentImageStateChanged(payloadData));
dispatch(() => {
let {subject} = getState();
if (subject.assetFinishCount == subject.assets.toJS().length) {
let item = subject.items.get(sid);
if (item.assetFinishCount == item.assets.toJS().length) {
let newParams = {
...params,
images: subject.assetsUrlStr,
images: item.assetsUrlStr,
}
dispatch(commitComment(newParams));
dispatch(commitComment(sid,newParams));
}
});
}
... ... @@ -436,16 +453,16 @@ export function commentImageStateChanged(payloadData) {
}
}
export function commentSuccess(json) {
export function commentSuccess(sid,json) {
return {
type: SUBJECT_REPLY_SUCCESS,
payload: json,
payload: {sid, json},
}
}
export function commentFail (error) {
export function commentFail (sid,error) {
return {
type: SUBJECT_COMMENTS_FAILURE,
payload: error,
type: SUBJECT_REPLY_FAILURE,
payload: {sid,error},
}
}
... ...
... ... @@ -9,8 +9,7 @@
*/
import Immutable, {List, Record} from 'immutable';
let InitialState = Record({
let item = new (Record({
isContentFetching: false,
contentError: null,
isCommentsFetching: false,
... ... @@ -21,7 +20,7 @@ let InitialState = Record({
nickName: '',
uid: 0,
url: ''
})),
})),
blocks: List(),// contentData order templateKey
browse: 0,
createTime: 0,
... ... @@ -59,6 +58,12 @@ let InitialState = Record({
inLikeAction: false,
largeImages:[],
}));
let InitialState = Record({
sid: -1,
items: List(),
item: item,
});
export default InitialState;
... ...
... ... @@ -49,15 +49,29 @@ export default function postingReducer(state = initialState, action) {
switch (action.type) {
case GO_TO_POST: {
return state.set('id', action.payload);
let sid = state.sid + 1;
// 获取新的初始状态item
let item = initialState.item;
// 设置item的value
item = item.set('id', action.payload);
// items新增item
let newItems = state.items.push(item);
let nextState = state.set('sid', sid)
.set('items', newItems);
return nextState;
// return state.set('id', action.payload);
}
case SUBJECT_CONTENT_REQUEST: {
let nextState = state.set('isContentFetching', true).set('contentError', null);
let sid = action.payload;
let item = state.items.get(sid);
item = item.set('isContentFetching', true).set('contentError', null);
let nextState = state.setIn(['items', sid], item);
return nextState;
}
break;
case SUBJECT_CONTENT_SUCCESS:{
let {sid,json} = action.payload;
let {
authorInfo,
... ... @@ -80,8 +94,9 @@ export default function postingReducer(state = initialState, action) {
hasPraise,
largeImages,
LZ,
} = action.payload;
let nextState = state.setIn(['authorInfo','headIcon'],authorInfo.headIcon||'')
} = json;
let item = state.items.get(sid);
item = item.setIn(['authorInfo','headIcon'],authorInfo.headIcon||'')
.setIn(['authorInfo','nickName'],authorInfo.nickName||'')
.setIn(['authorInfo','uid'],authorInfo.uid||'')
.setIn(['authorInfo','url'],authorInfo.url||'')
... ... @@ -94,7 +109,7 @@ export default function postingReducer(state = initialState, action) {
.set('isForumTop',isForumTop)
.set('isHot',isHot)
.set('isIndexTop',isIndexTop)
.set('postsTitle',decodeURI(postsTitle))
.set('postsTitle',postsTitle)
.set('praise',praise)
.set('praiseUsers',Immutable.fromJS(praiseUsers))
.set('publishTimeString',publishTimeString)
... ... @@ -106,81 +121,119 @@ export default function postingReducer(state = initialState, action) {
.set('largeImages',largeImages)
.set('hasPraise',hasPraise||'N');
if (shareGoods) {
nextState.setIn(['shareGoods','productName'],shareGoods.productName||'')
item.setIn(['shareGoods','productName'],shareGoods.productName||'')
.setIn(['shareGoods','productUrl'],shareGoods.productUrl||'')
.setIn(['shareGoods','salesPrice'],shareGoods.salesPrice||'')
.setIn(['shareGoods','goodsImage'],shareGoods.goodsImage||'')
}
let nextState = state.setIn(['items', sid], item);
return nextState;
}
break;
case SUBJECT_CONTENT_FAILURE: {
let nextState = state.set('isContentFetching', false).set('contentError', action.payload);
let {sid,error} = action.payload;
let item = state.items.get(sid);
item = item.set('isContentFetching', false).set('contentError', error);
let nextState = state.setIn(['items', sid], item);
return nextState;
}
break;
case SUBJECT_COMMENTS_SUCCESS:{
let {lastedTime, total, list, pageSize} = action.payload;
let {sid,json} = action.payload;
let item = state.items.get(sid);
let {lastedTime, total, list, pageSize} = json;
let tailCount = (total%pageSize)>0?1:0;
let totalPages = total/pageSize + tailCount;
let existedAry = state.commentList.toJS();
let existedAry = item.commentList.toJS();
let nextData = [...existedAry,...list];
let page = state.currentPage;
let page = item.currentPage;
page++;
let nextState = state.set('commentList',Immutable.fromJS(nextData))
item = item.set('commentList',Immutable.fromJS(nextData))
.set('lastedTime',lastedTime)
.set('totalPages',totalPages)
.set('currentPage',page)
.set('commentCount',total);
let nextState = state.setIn(['items', sid], item);
return nextState;
}
break;
case SUBJECT_COMMENTS_REQUEST:{
let nextState = state.set('isCommentsFetching', true).set('commentsError', null);
let sid = action.payload;
let item = state.items.get(sid);
item = item.set('isCommentsFetching', true).set('commentsError', null);
let nextState = state.setIn(['items', sid], item);
return nextState;
}
break;
case SUBJECT_COMMENTS_FAILURE:
let nextState = state.set('isCommentsFetching', false).set('commentsError', action.payload);
let {sid,error} = action.payload;
let item = state.items.get(sid);
item = item.set('isCommentsFetching', false).set('commentsError', error);
let nextState = state.setIn(['items', sid], item);
return nextState;
break;
case SUBJECT_ASSETS_SELECTED: {
let data = action.payload||[];
let nextState = state.set('assets',Immutable.fromJS(data));
let {sid,assets} = action.payload;
let data = assets||[];
let item = state.items.get(sid);
item = item.set('assets',Immutable.fromJS(data));
let nextState = state.setIn(['items', sid], item);
return nextState;
}
break;
case SUBJECT_REPLY_REQUEST: {
let nextState = state.set('isReplying',true).set('replyError',null);
let sid = action.payload;
let item = state.items.get(sid);
item = item.set('isReplying',true).set('replyError',null);
let nextState = state.setIn(['items', sid], item);
return nextState;
}
break;
case SUBJECT_REPLY_SUCCESS:{
let nextState = state.set('assets',Immutable.fromJS([]))
let {sid, json} = action.payload;
let item = state.items.get(sid);
item = item.set('assets',Immutable.fromJS([]))
.set('assetsUrlStr','')
.set('assetFinishCount',0)
.set('isReplying',false)
.set('replyError',error)
.set('replyError',error);
let nextState = state.setIn(['items', sid], item);
return nextState;
}
break;
case SUBJECT_REPLY_FAILURE: {
let nextState = state.set('isReplying',false).set('replyError',action.payload);
let {sid,error} = action.payload;
let item = state.items.get(sid);
item = item.set('isReplying',false).set('replyError',action.payload);
let nextState = state.setIn(['items', sid], item);
return nextState;
}
break;
case SUBJECT_REPLY_UPDATE: {
let {newStr,newCount} = action.payload;
let nextState = state.set('assetsUrlStr',newStr).set('assetFinishCount',newCount);
let {sid, newStr,newCount} = action.payload;
let item = state.items.get(sid);
item = item.set('assetsUrlStr',newStr).set('assetFinishCount',newCount);
let nextState = state.setIn(['items', sid], item);
return nextState;
}
case SUBJECT_LIKE_REQUEST: {
return state.set('hasPraise','Y');
let {sid,json} = action.payload;
let item = state.items.get(sid);
item = item.set('hasPraise','Y');
let nextState = state.setIn(['items', sid], item);
return nextState;
}
case SUBJECT_UNLIKE_REQUEST: {
return state.set('hasPraise','N');;
let {sid,json} = action.payload;
let item = state.items.get(sid);
item = item.set('hasPraise','N');
let nextState = state.setIn(['items', sid], item);
return nextState;
}
break;
case SUBJECT_DO_NOTHING:
... ... @@ -190,7 +243,7 @@ export default function postingReducer(state = initialState, action) {
return state;
break;
default:
return initialState;
return state;
break;
}
}
... ...
... ... @@ -633,7 +633,7 @@ function parseJson(json) {
blocks && blocks.map((item, i) => {
let contentData = item.contentData ? item.contentData : '';
if (desc === '' && item.templateKey === 'text') {
desc = decodeURI(contentData);
desc = contentData;
}
if (item.templateKey === 'image') {
... ... @@ -650,7 +650,7 @@ function parseJson(json) {
let createTime = item.createTime;
let timeagoStr = timeago(createTime);
let isLike = item.hasPraise === 'Y' ? true : false;
let title = item.postsTitle ? decodeURI(item.postsTitle) : '';
let title = item.postsTitle ? item.postsTitle : '';
if (title === '') {
title = desc;
desc = '';
... ... @@ -701,7 +701,7 @@ function parseReply(json) {
blocks && blocks.map((item, i) => {
let contentData = item.contentData ? item.contentData : '';
if (desc === '' && item.templateKey === 'text') {
desc = decodeURI(contentData);
desc = contentData;
}
if (item.templateKey === 'image') {
... ...
... ... @@ -110,7 +110,7 @@ export function userThatNotMePosts(sid) {
if (!item) {
return;
}
if (item.posts.isFetching || item.posts.error) {
return;
}
... ... @@ -170,7 +170,7 @@ function parseUserThatNotMePosts(json) {
blocks && blocks.map((item, i) => {
let contentData = item.contentData ? item.contentData : '';
if (desc === '' && item.templateKey === 'text') {
desc = decodeURI(contentData);
desc = contentData;
}
if (item.templateKey === 'image') {
... ... @@ -187,7 +187,7 @@ function parseUserThatNotMePosts(json) {
let createTime = item.createTime;
let timeagoStr = timeago(createTime);
let isLike = item.hasPraise === 'Y' ? true : false;
let title = item.postsTitle ? decodeURI(item.postsTitle) : '';
let title = item.postsTitle ? item.postsTitle : '';
title = title === '' ? desc : title;
let id = item.id ? item.id : 0;
... ...