_ = 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: ->
_defaultColumns: ->
c0 = new ThreadListColumn
name: "★"
flex: 0.2
resolver: (thread, parentComponent) ->
thread.toggleStar.apply(thread)}>
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
numMessages = (thread) ->
numMsg = thread.numMessages()
if numMsg < 1 then "" else numMsg
c2 = new ThreadListColumn
name: "Subject"
flex: 3
resolver: (thread) ->
{subject(thread)}
{numMessages(thread)}
c3 = new ThreadListColumn
name: "Snippet"
flex: 4
resolver: (thread) ->
{thread.snippet}
c4 = new ThreadListColumn
name: "Date"
flex: 1
resolver: (thread, parentComponent) ->
{parentComponent.threadTime()}
return [c0, c1, c2, c3, c4]
_threadHeaders: ->
return
# TODO: There's currently no styling for headers
# for col in @state.columns
#
# {col.name}
#
# The `numTags` attribute is only used to trigger a re-render of the
# ThreadListTabularItem when a tag gets added or removed (like a star).
# React's diffing engine does not detect the change the array nested
# deep inside of the thread and does not call render on the associated
# ThreadListTabularItem. Add the attribute fixes this.
_threadRows: ->
@state.threads.map (thread) =>
_columnFlex: ->
if @_colFlex? then return @_colFlex
@_colFlex = {}
for col in (@state.columns ? [])
@_colFlex[col.name] = col.flex
return @_colFlex