Sha256: 4d6cd80404bf38d2902f6a764a97c5a183a20eb89f55fb8b967a5580bf9d42c9

Contents?: true

Size: 1.76 KB

Versions: 4

Compression:

Stored size: 1.76 KB

Contents

import { Component, PropTypes } from 'react';
import { filter, propType }     from 'graphql-anywhere';
import gql                      from 'graphql-tag';
import { I18n }                 from 'react-i18nify';

import Comment                  from './comment.component';

import commentThreadFragment    from './comment_thread.fragment.graphql'

/**
 * Define a collection of comments. It represents a conversation with multiple users.
 * @class
 * @augments Component
 * @todo It doesn't handle multiple comments yet
 */
class CommentThread extends Component {
  render() {
    const { comment, session, votable } = this.props;

    return (
      <div>
        {this._renderTitle()}
        <div className="comment-thread">
          <Comment
            comment={filter(Comment.fragments.comment, comment)}
            session={session}
            votable={votable}
            isRootComment
          />
        </div>
      </div>
    );
  }

  /**
   * Render conversation title if comment has commments
   * @private
   * @returns {Void|DOMElement} - The conversation's title
   */
  _renderTitle() {
    const { comment: { author, hasComments } } = this.props;

    if (hasComments) {
      return (
        <h6 className="comment-thread__title">
          { I18n.t("components.comment_thread.title", { authorName: author.name }) }
        </h6>
      );
    }

    return null;
  }
}

CommentThread.fragments = {
  comment: gql`
    ${commentThreadFragment}
    ${Comment.fragments.comment}
  `
};

CommentThread.propTypes = {
  session: PropTypes.shape({
    user: PropTypes.any.isRequired
  }),
  comment: propType(CommentThread.fragments.comment).isRequired,
  votable: PropTypes.bool
};

CommentThread.defaultProps = {
  session: null,
  votable: false
};

export default CommentThread;

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
decidim-comments-0.0.6 app/frontend/comments/comment_thread.component.jsx
decidim-0.0.6 decidim-comments/app/frontend/comments/comment_thread.component.jsx
decidim-comments-0.0.5 app/frontend/comments/comment_thread.component.jsx
decidim-0.0.5 decidim-comments/app/frontend/comments/comment_thread.component.jsx