Mailspring/internal_packages/thread-list/lib/thread-list.cjsx
Ben Gotow 89e9cdef8d feat(*): draft icon, misc fixes, and WorkspaceStore / custom toolbar in secondary windows
Summary:
Features:
- ThreadListParticipants ignores drafts when computing participants, renders "Draft" label, pending design

- Put the WorkspaceStore in every window—means they all get toolbars and custom gumdrop icons on Mac OS X

Bug Fixes:

- Never display notifications for email the user just sent

- Fix obscure issue with DatabaseView trying to update metadata on items it froze. This resolves issue with names remaining bold after marking as read, drafts not appearing in message list immediately.

- When you pop out a draft, save it first and *wait* for the commit() promise to succeed.

- If you scroll very fast, you node.contentWindow can be null in eventedIframe

Other:

Make it OK to re-register the same component

Make it possible to unregister a hot window

Break the Sheet Toolbar out into it's own file to make things manageable

Replace `package.windowPropsReceived` with a store-style model where anyone can listen for changes to `windowProps`

When I put the WorkspaceStore in every window, I ran into a problem because the package was no longer rendering an instance of the Composer, it was declaring a root sheet with a composer in it. This meant that it was actually a React component that needed to listen to window props, not the package itself.

`atom` is already an event emitter, so I added a `onWindowPropsReceived` hook so that components can listen to window props as if they were listening to a store. I think this might be more flexible than only broadcasting the props change event to packages.

Test Plan: Run tests

Reviewers: evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D1592
2015-06-03 16:02:19 -07:00

132 lines
3.8 KiB
CoffeeScript

_ = require 'underscore'
React = require 'react'
classNames = require 'classnames'
{ListTabular, MultiselectList, RetinaImg} = require 'nylas-component-kit'
{timestamp, subject} = require './formatting-utils'
{Actions,
Utils,
Thread,
WorkspaceStore,
NamespaceStore} = require 'nylas-exports'
ThreadListParticipants = require './thread-list-participants'
ThreadListStore = require './thread-list-store'
class ThreadList extends React.Component
@displayName: 'ThreadList'
@containerRequired: false
componentWillMount: =>
labelComponents = (thread) =>
for label in @state.threadLabelComponents
LabelComponent = label.view
<LabelComponent thread={thread} />
lastMessageType = (thread) ->
myEmail = NamespaceStore.current()?.emailAddress
msgs = thread.metadata
return 'unknown' unless msgs and msgs instanceof Array
msgs = _.filter msgs, (m) -> m.isSaved() and not m.draft
msg = msgs[msgs.length - 1]
return 'unknown' unless msgs.length > 0
if thread.unread
return 'unread'
else if msg.from[0]?.email isnt myEmail or msgs.length is 1
return 'other'
else if Utils.isForwardedMessage(msg)
return 'forwarded'
else
return 'replied'
c1 = new ListTabular.Column
name: ""
resolver: (thread) =>
<div className="thread-icon thread-icon-#{lastMessageType(thread)}"></div>
c2 = new ListTabular.Column
name: "Name"
width: 200
resolver: (thread) =>
hasDraft = _.find (thread.metadata ? []), (m) -> m.draft
if hasDraft
<div style={display: 'flex'}>
<ThreadListParticipants thread={thread} />
<RetinaImg name="icon-draft-pencil.png" className="draft-icon" />
</div>
else
<ThreadListParticipants thread={thread} />
c3 = new ListTabular.Column
name: "Message"
flex: 4
resolver: (thread) =>
attachments = []
if thread.hasTagId('attachment')
attachments = <div className="thread-icon thread-icon-attachment"></div>
<span className="details">
<span className="subject">{subject(thread.subject)}</span>
<span className="snippet">{thread.snippet}</span>
{attachments}
</span>
c4 = new ListTabular.Column
name: "Date"
resolver: (thread) =>
<span className="timestamp">{timestamp(thread.lastMessageTimestamp)}</span>
@columns = [c1, c2, c3, c4]
@commands =
'core:remove-item': @_onArchive
'core:remove-and-previous': -> Actions.archiveAndPrevious()
'core:remove-and-next': -> Actions.archiveAndNext()
'application:reply': @_onReply
'application:reply-all': @_onReplyAll
'application:forward': @_onForward
@itemPropsProvider = (item) ->
className: classNames
'unread': item.isUnread()
render: =>
<MultiselectList
dataStore={ThreadListStore}
columns={@columns}
commands={@commands}
itemPropsProvider={@itemPropsProvider}
className="thread-list"
collection="thread" />
# Additional Commands
_onArchive: =>
if @_viewingFocusedThread() or ThreadListStore.view().selection.count() is 0
Actions.archive()
else
Actions.archiveSelection()
_onReply: ({focusedId}) =>
return unless focusedId? and @_viewingFocusedThread()
Actions.composeReply(threadId: focusedId)
_onReplyAll: ({focusedId}) =>
return unless focusedId? and @_viewingFocusedThread()
Actions.composeReplyAll(threadId: focusedId)
_onForward: ({focusedId}) =>
return unless focusedId? and @_viewingFocusedThread()
Actions.composeForward(threadId: focusedId)
# Helpers
_viewingFocusedThread: =>
if WorkspaceStore.layoutMode() is "list"
WorkspaceStore.topSheet() is WorkspaceStore.Sheet.Thread
else
true
module.exports = ThreadList