Authored by 盖剑秋

Comment list of post detail page. reviewed by redding.

... ... @@ -317,6 +317,7 @@ export default function community(platform) {
},
homeOnRight(state) {
// Actions.SubjectPost();
state.dispatch(startEditPost(state.getPostingState()));
},
/*
... ...
... ... @@ -8,6 +8,8 @@ import {
Image,
} from 'react-native'
import SlicedImage from '../../../common/components/SlicedImage';
export default class SubjectContent extends Component {
constructor(props) {
super(props);
... ...
... ... @@ -7,10 +7,12 @@ import {
ListView,
StyleSheet,
Image,
Dimensions,
} from 'react-native'
import UserBrief from '../home/UserBrief';
import SubjectContent from './SubjectContent'
import LoadMoreIndicator from '../../../common/components/LoadMoreIndicator';
export default class SubjectPost extends Component {
constructor(props) {
... ... @@ -31,7 +33,7 @@ export default class SubjectPost extends Component {
<UserBrief
avatar={rowData.headIcon}
name={rowData.nickName}
timeago={this.props.timeagoStr}
timeago={rowData.timeago}
isOwner={rowData.LZ}
onPressAvatar={() => {
this.props.onPressAvatar && this.props.onPressAvatar();
... ... @@ -61,26 +63,42 @@ export default class SubjectPost extends Component {
{this.renderLikeAvatar(rowData.praiseUsers)}
<Text style={styles.likeText}>{rowData.praise + '人点赞'}</Text>
</View>
<View style={styles.rightContainer}>
<View style={styles.rightLikeContainer}>
<Text style={styles.browseText}>{rowData.browse + '人看过'}</Text>
</View>
</View>
);
break;
case 'comments':
return (
<View style={styles.commentContainer}>
<UserBrief
avatar={rowData.headIcon}
name={rowData.nickName}
timeago={rowData.timeago}
isOwner={rowData.LZ}
onPressAvatar={() => {
this.props.onPressAvatar && this.props.onPressAvatar();
}}
/>
<SubjectContent blocks={rowData.blocks}/>
<View style={styles.commentSeparator}/>
</View>
);
break;
default:
break;
}
}
renderLikeAvatar(avatars) {
console.log(avatars);
if (avatars.length) {
avatars.reverse();
return (
<View style={styles.avatarPannel}>
{avatars.map((item, i)=> {
return (
<Image style={[styles.likeAvatar,{right:10*i}]} source={{uri:item.headIcon}}/>
<Image key={i} style={[styles.likeAvatar,{right:10*i}]} source={{uri:item.headIcon}}/>
);
})}
</View>
... ... @@ -94,11 +112,28 @@ export default class SubjectPost extends Component {
dataSource={this.dataSource.cloneWithRowsAndSections(this.props.dataBlob)}
renderRow={this.renderRow}
enableEmptySections={true}
onEndReached={() => {
this.props.onEndReached && this.props.onEndReached();
}}
renderFooter={()=>{
if (this.props.endReached) {
return <LoadMoreIndicator
isVisible={true}
text={'没有更多啦'}
/>
} else {
return <LoadMoreIndicator
isVisible={true}
animating={this.props.isFetching}
/>
}
}}
/>
);
}
}
let {width, height} = Dimensions.get('window');
const styles = StyleSheet.create({
container: {
top: 0,
... ... @@ -134,7 +169,7 @@ const styles = StyleSheet.create({
flex: 1,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-end'
justifyContent: 'flex-end',
},
likeAvatar: {
width: 30,
... ... @@ -143,7 +178,7 @@ const styles = StyleSheet.create({
},
likeText: {
fontSize: 14,
left: 10,
left: -10,
},
browseText: {
fontSize: 14,
... ... @@ -156,6 +191,17 @@ const styles = StyleSheet.create({
backgroundColor: 'white',
paddingLeft: 15,
},
commentContainer: {
paddingTop: 10,
paddingLeft: 15,
paddingRight: 15,
backgroundColor: 'white',
},
commentSeparator: {
backgroundColor: '#a0a0a0',
height: 0.5,
width: width-30,
},
headerRight: {
flex: 1,
flexDirection: 'row',
... ...
... ... @@ -75,8 +75,6 @@ class PostingContainer extends Component{
if (shouldHideTabBar(this.props.navigationState)) {
NativeModules.YH_CommunityHelper.hideTabBar();
}
}
_onGetBordList() {
... ...
... ... @@ -52,16 +52,21 @@ function mapDispatchToProps(dispatch) {
class SubjectPostContainer extends Component {
constructor(props) {
super(props);
this.onEndReached = this.onEndReached.bind(this);
}
componentDidMount () {
this.props.actions.requestPostContent(300);
this.props.actions.requestPostComments(300);
}
onEndReached() {
if (this.props.subject.currentPage>=this.props.subject.totalPages) {
return;
}
this.props.actions.requestPostComments(300, this.props.subject.lastedTime);
}
render() {
let {headIcon,nickName} = this.props.subject.authorInfo;
let timeagoStr = timeago().format(this.props.subject.createTime, 'zh_CN');
let header = {
headIcon,
nickName,
... ... @@ -74,6 +79,7 @@ class SubjectPostContainer extends Component {
praise: this.props.subject.praise,
browse: this.props.subject.browse,
}
let dataBlob = {
header : [header],
// 'title': [this.props.subject.postsTitle],
... ... @@ -98,18 +104,19 @@ class SubjectPostContainer extends Component {
],],
like: [likeData],
comments: this.props.subject.commentList.toJS(),
};
return (
<View style={styles.container}>
<SubjectPost
dataBlob={dataBlob}
onEndReached={this.onEndReached}
endReached={this.props.subject.currentPage>=this.props.subject.totalPages}
isFetching={this.props.subject.isCommentsFetching}
/>
</View>
);
}
constructDataBlob() {
}
}
let {width, height} = Dimensions.get('window');
... ...
... ... @@ -11,6 +11,7 @@ import Immutable, {List, Record} from 'immutable';
import {
NativeModules,
} from 'react-native';
import timeago from 'timeago.js';
const {
SUBJECT_CONTENT_REQUEST,
... ... @@ -74,10 +75,12 @@ export function requestPostComments(postsId, lastedTime) {
};
new PostingService().getPostComments(params)
.then(json => {
console.log(json);
dispatch(commentsRequestSuccess(json));
})
.catch(error => {
console.log(error);
dispatch(commentsRequestFailure(error));
});
}
... ... @@ -90,6 +93,32 @@ export function doRequestComments() {
}
export function commentsRequestSuccess(json) {
let {list} = json;
let newList = [];
list && list.map((obj,i)=> {
let {createTime, reply, replyTo, blocks} = obj;
let timeagoStr = timeago().format(createTime, 'zh_CN');
let newBlocks = [];
blocks && blocks.map((blockItem, i) => {
let {commentId,content,templateKey,orderBy} = blockItem;
let newItem = {
"contentData": content,
"order": orderBy,
"templateKey": templateKey,
};
newBlocks.push(newItem);
})
let newObj={
timeago: timeagoStr,
headIcon: reply.headIcon,
nickName: reply.nickName,
LZ:false,
blocks: newBlocks,
}
newList.push(newObj);
})
json.list = newList;
return {
type: SUBJECT_COMMENTS_SUCCESS,
payload: json,
... ...
/**
/**
* # sunbjectPostInitialState.js
*
*
... ... @@ -43,6 +43,9 @@ let InitialState = Record({
publishTimeString: '',
shareProductSkn: 0,
LZ: false,//楼主
lastedTime: 0,
totalPages: 0,
currentPage: 0,
commentList: List(),//
});
... ...
... ... @@ -94,9 +94,18 @@ export default function postingReducer(state = initialState, action) {
}
break;
case SUBJECT_COMMENTS_SUCCESS:{
let existedAry = state.commentList.toJS;
let nextData = [...existedAry,...action.payload];
let nextState = state.set('commentList',Immutable.fromJS(nextData));
let {lastedTime, total, list, pageSize} = action.payload;
let tailCount = (total%pageSize)>0?1:0;
let totalPages = total/pageSize + tailCount;
let existedAry = state.commentList.toJS();
let nextData = [...existedAry,...list];
let page = state.currentPage;
page++;
let nextState = state.set('commentList',Immutable.fromJS(nextData))
.set('lastedTime',lastedTime)
.set('totalPages',totalPages)
.set('currentPage',page);
return nextState;
}
break;
... ...