import React, { Component } from 'react';
import commentsRepository from './CommentsRepository';
import style from './Comments.css';
class Summary extends Component {
constructor(props) {
super(props);
this.state = { group: props.group };
}
componentWillReceiveProps(nextProps) {
this.setState({group: nextProps.group});
}
nextPage(e) {
e.preventDefault();
var skip = this.state.group.comments.length;
var limit = this.props.size || this.state.group.size;
commentsRepository.loadComments(this.props.commentsId, skip, limit);
}
render() {
if (this.state.group === undefined) {
return null;
}
var count = this.state.group.comments ? this.state.group.comments.length : 0;
var total = this.state.group.count || 0;
if (count === 0 || count >= total) {
return null;
}
return (
<div className={style['comments-summary']}>
<a href="#" data-remote="true" onClick={this.nextPage.bind(this)}><i className="fa mr-1 fa-caret-down"></i>View more comments</a>
<span className={style['record-display']}>{count} of {total}</span>
</div>
)
}
}
export default Summary;
|