<commit_before>React.defineClass('ReactSubCommentsAdd')
  getInitialState: ->
    text: ''

  model_for_text: ->
    model = new SubComment
      content: @state.text
      created_by: currentUser.toJSON()

  submit: ->
    model = @model_for_text()
    @props.addToCollection.add(model)
    model.save {},
      error: =>
        @props.addToCollection.remove(model)
        FactlinkApp.NotificationCenter.error "Your comment '#{model.get('content')}' could not be posted, please try again."
    @refs.text_area.updateText ''

  updateText: (text)->
    @setState text: $.trim(text)

  is_valid: ->
    @model_for_text().isValid()

  render: ->
    R.div className: 'sub-comment-add spec-sub-comments-form',
      ReactTextArea
        placeholder: 'Leave a reply'
        onChange: @updateText
        defaultValue: ''
        ref: 'text_area'
        onSubmit: @submit
      _button ["button button-confirm button-small spec-submit",
               disabled: !@is_valid(),
               onClick: @submit],
        Factlink.Global.t.post_subcomment

window.ReactSubCommentList = React.createBackboneClass
  getInitialState: ->
    loading: true

  componentDidMount: ->
    @model().fetch
      success: => @setState loading: false
    @setState loading: true

  render: ->
    if @model().size() == 0 && @state.loading
      ReactLoadingIndicator()
    else
      R.div className: 'sub-comments',
        @model().map (sub_comment) =>
          ReactSubComment(model: sub_comment)
        if Factlink.Global.signed_in
          ReactSubCommentsAdd(addToCollection: @model())

window.ReactSubComments = React.createClass
  render: ->
    ReactSubCommentList model: @props.model.sub_comments()<commit_msg>display loading more in a react manner<commit_after>React.defineClass('ReactSubCommentsAdd')
  getInitialState: ->
    text: ''

  model_for_text: ->
    model = new SubComment
      content: @state.text
      created_by: currentUser.toJSON()

  submit: ->
    model = @model_for_text()
    @props.addToCollection.add(model)
    model.save {},
      error: =>
        @props.addToCollection.remove(model)
        FactlinkApp.NotificationCenter.error "Your comment '#{model.get('content')}' could not be posted, please try again."
    @refs.text_area.updateText ''

  updateText: (text)->
    @setState text: $.trim(text)

  is_valid: ->
    @model_for_text().isValid()

  render: ->
    R.div className: 'sub-comment-add spec-sub-comments-form',
      ReactTextArea
        placeholder: 'Leave a reply'
        onChange: @updateText
        defaultValue: ''
        ref: 'text_area'
        onSubmit: @submit
      _button ["button button-confirm button-small spec-submit",
               disabled: !@is_valid(),
               onClick: @submit],
        Factlink.Global.t.post_subcomment

window.ReactSubCommentList = React.createBackboneClass
  componentDidMount: ->
    @props.model.on 'sync request', (-> @forceUpdate()), @

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

  render: ->
    if @model().size() == 0 && @model().loading()
      ReactLoadingIndicator()
    else
      R.div className: 'sub-comments',
        @model().map (sub_comment) =>
          ReactSubComment(model: sub_comment)
        if Factlink.Global.signed_in
          ReactSubCommentsAdd(addToCollection: @model())

window.ReactSubComments = React.createClass
  render: ->
    ReactSubCommentList model: @props.model.sub_comments()
{'fraction_non_alphanumeric': 0.1272674078408426, 'fraction_numerical': 0.0005851375073142189, 'mean_word_length': 2.8852272727272728, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '2368513', 'n_tokens_mistral': 1026, 'n_tokens_neox': 1027, 'n_words': 204}