/* eslint-disable no-return-assign, react/no-unused-prop-types, max-lines */ import { Component, PropTypes } from 'react'; import { graphql } from 'react-apollo'; import gql from 'graphql-tag'; import { I18n, Translate } from 'react-i18nify'; import uuid from 'uuid'; import classnames from 'classnames'; import Icon from '../application/icon.component'; import addCommentMutation from './add_comment_form.mutation.graphql'; import commentThreadFragment from './comment_thread.fragment.graphql' import commentFragment from './comment.fragment.graphql'; import commentDataFragment from './comment_data.fragment.graphql'; import upVoteFragment from './up_vote.fragment.graphql'; import downVoteFragment from './down_vote.fragment.graphql'; import addCommentFormSessionFragment from './add_comment_form_session.fragment.graphql'; import addCommentFormCommentableFragment from './add_comment_form_commentable.fragment.graphql'; /** * Renders a form to create new comments. * @class * @augments Component */ export class AddCommentForm extends Component { constructor(props) { super(props); this.state = { disabled: true, error: false, alignment: 0 }; } render() { return (
{this._renderHeading()} {this._renderAccountMessage()} {this._renderOpinionButtons()} {this._renderForm()}
); } /** * Render the form heading based on showTitle prop * @private * @returns {Void|DOMElement} - The heading or an empty element */ _renderHeading() { const { showTitle } = this.props; if (showTitle) { return (
{ I18n.t("components.add_comment_form.title") }
); } return null; } /** * Render a message telling the user to sign in or sign up to leave a comment. * @private * @returns {Void|DOMElement} - The message or an empty element. */ _renderAccountMessage() { const { session } = this.props; if (!session) { return (

); } return null; } /** * Render the add comment form if session is present. * @private * @returns {Void|DOMElement} - The add comment form on an empty element. */ _renderForm() { const { session, submitButtonClassName, commentable: { id, type } } = this.props; const { disabled } = this.state; if (session) { return (
this._addComment(evt)}> {this._renderCommentAs()}
{this._renderTextArea()} {this._renderTextAreaError()}
); } return null; } /** * Render the form heading based on showTitle prop * @private * @returns {Void|DOMElement} - The heading or an empty element */ _renderTextArea() { const { commentable: { id, type }, autoFocus, maxLength } = this.props; const { error } = this.state; const className = classnames({ 'is-invalid-input': error }); let textAreaProps = { ref: (textarea) => {this.bodyTextArea = textarea}, id: `add-comment-${type}-${id}`, className, rows: "4", maxLength, required: "required", pattern: `^(.){0,${maxLength}}$`, placeholder: I18n.t("components.add_comment_form.form.body.placeholder"), onChange: (evt) => this._checkCommentBody(evt.target.value) }; if (autoFocus) { textAreaProps.autoFocus = 'autoFocus'; } return (