<commit_before>Backbone = require 'backbone'
{ QUERY, PROFILE_CHANNELS, SORT } = require("sharify").data
mediator = require '../../../lib/mediator.coffee'
ChannelGroupView = require '../../../components/channel_block_group/view.coffee'

template = -> require('../templates/partials/_channel_groups.jade') arguments...

class ProfileView extends Backbone.View
  loading: false
  disabled: false
  threshold: -500
  page: 2

  initialize: ->
    @timer = setInterval @maybeLoad, 150

  maybeLoad: =>
    return false if @loading or 
      @disabled or 
      mediator.shared.state.get 'lightbox'

    total = document.body.scrollHeight
    scrollPos = (document.documentElement.scrollTop || document.body.scrollTop)
    progress = scrollPos + window.innerHeight * 4

    if (total - progress < @threshold)
      @loadNextPage() 

  loadNextPage: ->
    @loading = true
    $.ajax 
      data: 
        page: @page
        q: QUERY
        sort: SORT
      url: "/api/#{sd.USER.slug}/profile"
      success: (response) =>
        @page++
        @loading = false

        if response.channels.length
          $('.profile').append template 
            channels: response.channels
          
          @setUpChannelGroupViews(response.channels)
        else
          @disabled = true

  setUpChannelGroupViews: (channels) ->
    for channel in channels
      view = new ChannelGroupView
        channel: channel
        el: @$(".ChannelBlockGroup[data-id=#{channel.id}]")
      
      view.initBlockViews()
      
module.exports.init = ->
  view = new ProfileView
    el: $('.profile')

  view.setUpChannelGroupViews(PROFILE_CHANNELS)<commit_msg>Initialize metaAttribute and pathView<commit_after>Backbone = require 'backbone'
{ QUERY, PROFILE_CHANNELS, SORT, USER } = require("sharify").data
mediator = require '../../../lib/mediator.coffee'
User = require "../../../models/user.coffee"
PathView = require '../../../components/path/client/path_view.coffee'
MetaEditableAttributeView = require '../../../components/editable_attribute/client/meta_editable_attribute_view.coffee'
ChannelGroupView = require '../../../components/channel_block_group/view.coffee'

template = -> require('../templates/partials/_channel_groups.jade') arguments...

class ProfileView extends Backbone.View
  loading: false
  disabled: false
  threshold: -500
  page: 2

  initialize: ->
    @timer = setInterval @maybeLoad, 150

  maybeLoad: =>
    return false if @loading or 
      @disabled or 
      mediator.shared.state.get 'lightbox'

    total = document.body.scrollHeight
    scrollPos = (document.documentElement.scrollTop || document.body.scrollTop)
    progress = scrollPos + window.innerHeight * 4

    if (total - progress < @threshold)
      @loadNextPage() 

  loadNextPage: ->
    @loading = true
    $.ajax 
      data: 
        page: @page
        q: QUERY
        sort: SORT
      url: "/api/#{sd.USER.slug}/profile"
      success: (response) =>
        @page++
        @loading = false

        if response.channels.length
          $('.profile').append template 
            channels: response.channels
          
          @setUpChannelGroupViews(response.channels)
        else
          @disabled = true

  setUpChannelGroupViews: (channels) ->
    for channel in channels
      view = new ChannelGroupView
        channel: channel
        el: @$(".ChannelBlockGroup[data-id=#{channel.id}]")
      
      view.initBlockViews()
      
module.exports.init = ->
  user = new User USER

  view = new ProfileView
    el: $('.profile')

  view.setUpChannelGroupViews(PROFILE_CHANNELS)

  new PathView
    el: $('section.path--header')
    model: user

  new MetaEditableAttributeView
    model: user
    el: $("#metadata--about .metadata__content")
    _attribute: 'description'
    _kind: 'markdown'
    wait: true
{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.004201680672268907, 'mean_word_length': 2.6035950804162726, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '5370650', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1081, 'n_words': 247}