<commit_before>window.ReactSubComments = React.createBackboneClass
  displayName: 'ReactSubComments'
  mixins: [UpdateOnSignInOrOutMixin]
  propTypes:
    fact_opinionators: React.PropTypes.instanceOf(Opinionators).isRequired
    model: React.PropTypes.instanceOf(SubComments).isRequired

  componentWillMount: ->
    @model().fetch()

  render: ->
    _div [],
      _div ['loading-indicator-centered'],
        ReactLoadingIndicator
          model: @model()
      @model().map (sub_comment) =>
        ReactSubComment
          model: sub_comment
          key: sub_comment.get('id')
          fact_opinionators: @props.fact_opinionators
      if FactlinkApp.signedIn()
        ReactSubCommentsAdd model: @model()

ReactSubCommentsAdd = React.createBackboneClass
  displayName: 'ReactSubCommentsAdd'

  getInitialState: ->
    text: ''
    opened: false

  _subComment: ->
    new SubComment
      content: $.trim(@state.text)
      created_by: currentUser.toJSON()

  _submit: ->
    sub_comment = @_subComment()
    return unless sub_comment.isValid()

    @model().add(sub_comment)
    sub_comment.saveWithState()

    @refs.textarea.updateText ''
    @setState opened: false

  _onTextareaChange: (text) ->
    @setState(text: text)
    @setState(opened: true) if text.length > 0

  render: ->
    _div ['sub-comment-add', 'spec-sub-comments-form'],
      ReactTextArea
        ref: 'textarea'
        placeholder: 'Leave a reply'
        storageKey: "add_subcomment_to_comment_#{@model().parentModel.id}"
        onChange: @_onTextareaChange
        onSubmit: @_submit
      if @state.opened
        _button ["button-confirm button-small spec-submit",
          disabled: !@_subComment().isValid()
          onClick: @_submit
        ],
          Factlink.Global.t.post_subcomment
<commit_msg>Use ReactSigninPopover when adding subcomments<commit_after>window.ReactSubComments = React.createBackboneClass
  displayName: 'ReactSubComments'
  propTypes:
    fact_opinionators: React.PropTypes.instanceOf(Opinionators).isRequired
    model: React.PropTypes.instanceOf(SubComments).isRequired

  componentWillMount: ->
    @model().fetch()

  render: ->
    _div [],
      _div ['loading-indicator-centered'],
        ReactLoadingIndicator
          model: @model()
      @model().map (sub_comment) =>
        ReactSubComment
          model: sub_comment
          key: sub_comment.get('id')
          fact_opinionators: @props.fact_opinionators
      ReactSubCommentsAdd model: @model()

ReactSubCommentsAdd = React.createBackboneClass
  displayName: 'ReactSubCommentsAdd'

  getInitialState: ->
    text: ''
    opened: false

  _subComment: ->
    new SubComment
      content: $.trim(@state.text)
      created_by: currentUser.toJSON()

  _submit: ->
    sub_comment = @_subComment()
    return unless sub_comment.isValid()

    @model().add(sub_comment)
    sub_comment.saveWithState()

    @refs.textarea.updateText ''
    @setState opened: false

  _onTextareaChange: (text) ->
    @setState(text: text)
    @setState(opened: true) if text.length > 0

  render: ->
    _div ['sub-comment-add', 'spec-sub-comments-form'],
      ReactTextArea
        ref: 'textarea'
        placeholder: 'Leave a reply'
        storageKey: "add_subcomment_to_comment_#{@model().parentModel.id}"
        onChange: @_onTextareaChange
        onSubmit: => @refs.signinPopover.submit()
      if @state.opened
        _button ["button-confirm button-small spec-submit",
          disabled: !@_subComment().isValid()
          onClick: => @refs.signinPopover.submit()
        ],
          Factlink.Global.t.post_subcomment
          ReactSigninPopover
            ref: 'signinPopover'
            onSubmit: @_submit

{'fraction_non_alphanumeric': 0.1131514987847691, 'fraction_numerical': 0.0005401026194977045, 'mean_word_length': 2.969989281886388, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6035235', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1120, 'n_words': 201}