<commit_before>kd             = require 'kd'
React          = require 'kd-react'
KDReactorMixin = require 'app/flux/reactormixin'
ActivityFlux   = require 'activity/flux'
immutable      = require 'immutable'
classnames     = require 'classnames'

module.exports = class ChannelThreadPane extends React.Component

  { getters } = ActivityFlux

  getDataBindings: ->
    return {
      channelThread         : getters.selectedChannelThread
      channelThreadMessages : getters.selectedChannelThreadMessages
      messageThread         : getters.selectedMessageThread
      messageThreadComments : getters.selectedMessageThreadComments
      popularMessages       : getters.selectedChannelPopularMessages
    }


  constructor: (props) ->

    super props

    @state =
      channelThread         : immutable.Map()
      channelThreadMessages : immutable.List()
      messageThread         : immutable.Map()
      messageThreadComments : immutable.List()
      popularMessages       : immutable.List()


  componentDidMount: -> reset @props


  componentWillReceiveProps: (nextProps) -> reset nextProps


  renderFeed: ->
    return null  unless @props.feed

    React.cloneElement @props.feed,
      thread   : @state.channelThread
      messages : @state.popularMessages


  renderChat: ->
    return null  unless @props.chat

    React.cloneElement @props.chat,
      thread   : @state.channelThread
      messages : @state.channelThreadMessages


  renderPost: ->

    return null  unless @props.post

    React.cloneElement @props.post,
      thread        : @state.messageThread
      messages      : @state.messageThreadComments
      channelThread : @state.channelThread


  renderChannelSidebar: -> null


  getClassName: ->

    classnames(
      ChannelThreadPane: yes
      'is-withFeed': @props.feed
      'is-withChat': @props.chat
      'is-withPost': @props.post
    )


  render: ->
    <div className={@getClassName()}>
      <section className="ChannelThreadPane-feedWrapper">
        {@renderFeed()}
      </section>
      <section className="ChannelThreadPane-chatWrapper">
        {@renderChat()}
      </section>
      <section className="ChannelThreadPane-postWrapper">
        {@renderPost()}
      </section>
      {@renderChannelSidebar()}
    </div>


React.Component.include.call ChannelThreadPane, [KDReactorMixin]

reset = (props) ->

  { channelName, postSlug } = props.params
  { thread, channel: channelActions, message: messageActions } = ActivityFlux.actions

  if channelName
    channelActions.loadChannelByName(channelName).then ({ channel }) ->
      thread.changeSelectedThread channel.id
      channelActions.loadPopularMessages channel.id

  if postSlug
    messageActions.loadMessageBySlug(postSlug).then ({ message }) ->
      messageActions.changeSelectedMessage message.id


<commit_msg>activity: add render ThreadSidebar method<commit_after>kd             = require 'kd'
React          = require 'kd-react'
KDReactorMixin = require 'app/flux/reactormixin'
ActivityFlux   = require 'activity/flux'
immutable      = require 'immutable'
classnames     = require 'classnames'
ThreadSidebar  = require 'activity/components/threadsidebar'

module.exports = class ChannelThreadPane extends React.Component

  { getters } = ActivityFlux

  getDataBindings: ->
    return {
      channelThread         : getters.selectedChannelThread
      channelThreadMessages : getters.selectedChannelThreadMessages
      messageThread         : getters.selectedMessageThread
      messageThreadComments : getters.selectedMessageThreadComments
      popularMessages       : getters.selectedChannelPopularMessages
    }


  constructor: (props) ->

    super props

    @state =
      channelThread         : immutable.Map()
      channelThreadMessages : immutable.List()
      messageThread         : immutable.Map()
      messageThreadComments : immutable.List()
      popularMessages       : immutable.List()


  componentDidMount: -> reset @props


  componentWillReceiveProps: (nextProps) -> reset nextProps


  renderFeed: ->
    return null  unless @props.feed

    React.cloneElement @props.feed,
      thread   : @state.channelThread
      messages : @state.popularMessages


  renderChat: ->
    return null  unless @props.chat

    React.cloneElement @props.chat,
      thread   : @state.channelThread
      messages : @state.channelThreadMessages


  renderPost: ->

    return null  unless @props.post

    React.cloneElement @props.post,
      thread        : @state.messageThread
      messages      : @state.messageThreadComments
      channelThread : @state.channelThread


  renderSidebar: ->
    <ThreadSidebar
      channelThread={@state.channelThread}
      popularMessages={@state.popularMessages}
      channelParticipants={@state.channelParticipants}/>


  getClassName: ->

    classnames(
      ChannelThreadPane: yes
      'is-withFeed': @props.feed
      'is-withChat': @props.chat
      'is-withPost': @props.post
    )


  render: ->
    <div className={@getClassName()}>
      <section className="ChannelThreadPane-feedWrapper">
        {@renderFeed()}
      </section>
      <section className="ChannelThreadPane-chatWrapper">
        {@renderChat()}
      </section>
      <section className="ChannelThreadPane-postWrapper">
        {@renderPost()}
      </section>
      {@renderChannelSidebar()}
    </div>


React.Component.include.call ChannelThreadPane, [KDReactorMixin]

reset = (props) ->

  { channelName, postSlug } = props.params
  { thread, channel: channelActions, message: messageActions } = ActivityFlux.actions

  if channelName
    channelActions.loadChannelByName(channelName).then ({ channel }) ->
      thread.changeSelectedThread channel.id
      channelActions.loadPopularMessages channel.id

  if postSlug
    messageActions.loadMessageBySlug(postSlug).then ({ message }) ->
      messageActions.changeSelectedMessage message.id



{'fraction_non_alphanumeric': 0.09477068877982738, 'fraction_numerical': 0.0, 'mean_word_length': 3.023144996596324, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 46, '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': '6270611', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1575, 'n_words': 312}