<commit_before>class App.Views.Threads extends Backbone.View
  template: JST['app/templates/threads.us']
  className: 'loading'

  events:
    'change input[name=notifications-state]': 'stateChange'
    'click #mark-all-read': 'read'

  initialize: ->
    @listenTo @collection, 'add', @add
    @listenTo @collection, 'reset', @addAll
    @listenTo @collection, 'request', @startPaginating
    @listenTo @collection, 'sync', @donePaginating

    @listenToOnce @collection, 'sync', =>
      # FIXME: this should be bound in #render, but for some reason the scroll
      # event doesn't work when this is there.
      @$content = @$('.content').on('scroll', _.debounce(@paginate, 50))

      # FIXME: this belongs somewhere else
      $('#toggle-lists').attr('checked', false) # Collapse the menu on mobile

    @stateChange()

  render: ->
    @$el.html @template()
    app.trigger 'render', @
    @$list = @$('.notification-list')
    @

  add: (notification) ->
    view = new App.Views.Notification(model: notification)
    @$list.append(view.render().el)

  addAll: ->
    @$list.empty()
    @collection.each(@add, @)

  read: (e) ->
    e.preventDefault()
    if window.confirm("Are you sure you want to mark all these as read?")
      @collection.read()

  shouldShowAll: ->
    @$('input[name=notifications-state]:checked').val() == 'all'

  stateChange: ->
    @$el.addClass('loading')
    @collection.data.all = @shouldShowAll()
    @collection.fetch(reset: true).then(@paginate)

  paginate: =>
    return if @isPaginating || @collection.donePaginating || !@shouldPaginate()
    @collection.paginate().done(@paginate)

  shouldPaginate: ->
    @$content.children().height() - @$content.scrollTop() < @$content.height() + 300

  hide: ->
    @$el.detach()

  show: ->

  startPaginating: ->
    @isPaginating = true
    @$el.addClass('paginating')

  donePaginating: ->
    @isPaginating = false
    @$el.removeClass('loading paginating')<commit_msg>fix inifinite loading indicator<commit_after>class App.Views.Threads extends Backbone.View
  template: JST['app/templates/threads.us']
  className: 'loading'

  events:
    'change input[name=notifications-state]': 'stateChange'
    'click #mark-all-read': 'read'

  initialize: ->
    @listenTo @collection, 'add', @add
    @listenTo @collection, 'reset', @addAll

    @listenToOnce @collection, 'sync', =>
      # FIXME: this should be bound in #render, but for some reason the scroll
      # event doesn't work when this is there.
      @$content = @$('.content').on('scroll', _.debounce(@paginate, 50))

      # FIXME: this belongs somewhere else
      $('#toggle-lists').attr('checked', false) # Collapse the menu on mobile

      @$el.removeClass('loading')

    @stateChange()

  render: ->
    @$el.html @template()
    app.trigger 'render', @
    @$list = @$('.notification-list')
    @

  add: (notification) ->
    view = new App.Views.Notification(model: notification)
    @$list.append(view.render().el)

  addAll: ->
    @$list.empty()
    @collection.each(@add, @)

  read: (e) ->
    e.preventDefault()
    if window.confirm("Are you sure you want to mark all these as read?")
      @collection.read()

  shouldShowAll: ->
    @$('input[name=notifications-state]:checked').val() == 'all'

  stateChange: ->
    @$el.addClass('loading')
    @collection.data.all = @shouldShowAll()
    @collection.fetch(reset: true).then(@paginate)

  paginate: =>
    return if @isPaginating || @collection.donePaginating || !@shouldPaginate()
    @startPaginating
    @collection.paginate().then(@donePaginating).done(@paginate)

  shouldPaginate: ->
    @$content.children().height() - @$content.scrollTop() < @$content.height() + 300

  hide: ->
    @$el.detach()

  show: ->

  startPaginating: ->
    @isPaginating = true
    @$el.addClass('paginating')

  donePaginating: =>
    @isPaginating = false
    @$el.removeClass('paginating')
{'fraction_non_alphanumeric': 0.16777834787070292, 'fraction_numerical': 0.002565418163160595, 'mean_word_length': 3.486766398158803, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '4793788', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1243, 'n_words': 271}