All files Summary.js

100% Statements 14/14
91.67% Branches 11/12
100% Functions 4/4
100% Lines 14/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47            36x   36x       34x       2x   2x 2x   2x       70x 1x     69x 69x   69x 43x     26x                    
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;