_ = require 'underscore-plus'
React = require 'react'
{ComponentRegistry} = require 'inbox-exports'
ThreadListMixin = require './thread-list-mixin.cjsx'
ThreadListColumn = require("./thread-list-column")
ThreadListTabularItem = require './thread-list-tabular-item.cjsx'
module.exports =
ThreadListTabular = React.createClass
mixins: [ComponentRegistry.Mixin, ThreadListMixin]
displayName: 'ThreadListTabular'
components: ["Participants"]
getInitialState: ->
columns: @_defaultColumns()
threadLabelComponents: ComponentRegistry.findAllByRole("thread label")
componentWillUpdate: ->
@_colFlex = null
componentWillMount: ->
@unlisteners = []
@unlisteners.push ComponentRegistry.listen (event) =>
@setState
threadLabelComponents: ComponentRegistry.findAllByRole("thread label")
componentWillUnmount: ->
unlisten() for unlisten in @unlisteners
render: ->
{@_threadHeaders()}
{@_threadRows()}
_defaultColumns: ->
c1 = new ThreadListColumn
name: "Name"
flex: 2
resolver: (thread, parentComponent) =>
Participants = @state.Participants
subject = (thread) ->
if (thread.subject ? "").trim().length is 0
return (No Subject)
else return thread.subject
labelComponents = (thread) =>
for label in @state.threadLabelComponents
LabelComponent = label.view
c2 = new ThreadListColumn
name: "Subject"
flex: 6
resolver: (thread) ->
{subject(thread)}
{thread.snippet}
{labelComponents(thread)}
c3 = new ThreadListColumn
name: "Date"
flex: 1
resolver: (thread, parentComponent) -> parentComponent.threadTime()
return [c1, c2, c3]
_threadHeaders: ->
for col in @state.columns
{col.name}
_threadRows: ->
@state.threads.map (thread) =>
_columnFlex: ->
if @_colFlex? then return @_colFlex
@_colFlex = {}
for col in (@state.columns ? [])
@_colFlex[col.name] = col.flex
return @_colFlex