All files Comment.js

100% Statements 11/11
100% Branches 2/2
100% Functions 4/4
100% Lines 11/11
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 48 49                  83x 83x   83x       33x       5x 5x           121x 4x 4x   117x                       121x          
import 'datejs';
import React, { Component } from 'react';
import Markdown from 'react-remarkable';
import Header from './Header';
import Form from './Form';
import style from './Comments.css';
 
class Comment extends Component {
  constructor(props) {
    super(props);
    this.state = { editionMode: false, comment: props.comment };
 
    this.editComment = this.editComment.bind(this);
  }
 
  componentWillReceiveProps(nextProps) {
    this.setState({comment: nextProps.comment, editionMode: false});
  }
 
  editComment(e) {
    e.preventDefault();
    this.setState({ editionMode: !this.state.editionMode, comment: this.state.comment });
  }
 
  render() {
    var view;
 
    if (this.state.editionMode) {
      var key = 'comment-form-' + this.state.comment._id;
      view = <Form key={key} commentsId={this.props.commentsId} comment={this.state.comment} cancel={this.editComment} />
    } else {
      view = (
        <div className={style.comment} data-comment-id={this.state.comment._id}>
          <a href="#" onClick={this.editComment} className={style.edit}>Edit</a>
          <span className={style.date}>{new Date(this.state.comment.updatedAt).toString('MMM d, hh:mmtt')}</span>
          <Header comment={this.state.comment} />
          <div className={style.text}>
            <Markdown>{this.state.comment.text}</Markdown>
          </div>
        </div>
      );
    }
 
    return view;
  }
}
 
export default Comment;