Mailspring/internal_packages/thread-list/lib/thread-list-columns.cjsx
Ben Gotow 8b3f7f0578 feat(outbox): Sending status now appears beside drafts
Summary:
This diff adds an "OutboxStore" which reflects the TaskQueue and
adds a progress bar / cancel button to drafts which are currently sending.

- Sending state is different from things like Send later because drafts
  which are sending shouldn't be editable. You should have to stop them
  from sending before editing. I think we can implement "Send Later"
  indicators, etc. with a simple InjectedComponentSet on the draft list
  rows, but the OutboxStore is woven into the DraftList query subscription
  so every draft has a `uploadTaskId`.

- The TaskQueue now saves periodically (every one second) when there are
  "Processing" tasks. This is not really necessary, but makes it super
  easy for tasks to expose "progress", because they're essentially
  serialized and propagated to all windows every one second with the
  current progress value. Kind of questionable, but super convenient.

- I also cleaned up ListTabular and MultiselectList a bit because they
  applied the className prop to an inner element and not the top one.

- If a DestroyDraft task is created for a draft without a server id, it
  ends with Task.Status.Continue and not Failed.

- The SendDraftTask doesn't delete uploads until the send actually goes
  through, in case the app crashes and it forgets the file IDs it created.

Test Plan: Tests coming soon

Reviewers: juan, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D2524
2016-02-04 14:14:24 -08:00

143 lines
4.2 KiB
CoffeeScript

_ = require 'underscore'
React = require 'react'
classNames = require 'classnames'
{ListTabular,
RetinaImg,
MailLabel,
MailImportantIcon,
InjectedComponentSet} = require 'nylas-component-kit'
{Thread,
AccountStore,
CategoryStore,
FocusedPerspectiveStore} = require 'nylas-exports'
{ThreadArchiveQuickAction,
ThreadTrashQuickAction} = require './thread-list-quick-actions'
{timestamp,
subject} = require './formatting-utils'
ThreadListParticipants = require './thread-list-participants'
ThreadListStore = require './thread-list-store'
ThreadListIcon = require './thread-list-icon'
c1 = new ListTabular.Column
name: ""
resolver: (thread) =>
[
<ThreadListIcon key="thread-list-icon" thread={thread} />
<MailImportantIcon
key="mail-important-icon"
thread={thread}
showIfAvailableForAnyAccount={true} />
<InjectedComponentSet
key="injected-component-set"
inline={true}
containersRequired={false}
matching={role: "ThreadListIcon"}
className="thread-injected-icons"
exposedProps={thread: thread}/>
]
c2 = new ListTabular.Column
name: "Participants"
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"
mode={RetinaImg.Mode.ContentPreserve} />
</div>
else
<ThreadListParticipants thread={thread} />
c3LabelComponentCache = {}
c3 = new ListTabular.Column
name: "Message"
flex: 4
resolver: (thread) =>
attachment = []
labels = []
if thread.hasAttachments
attachment = <div className="thread-icon thread-icon-attachment"></div>
if AccountStore.accountForId(thread.accountId).usesLabels()
currentCategories = FocusedPerspectiveStore.current().categories() ? []
ignored = [].concat(currentCategories, CategoryStore.hiddenCategories(thread.accountId))
ignoredIds = _.pluck(ignored, 'id')
for label in (thread.sortedCategories())
continue if label.id in ignoredIds
c3LabelComponentCache[label.id] ?= <MailLabel label={label} key={label.id} />
labels.push c3LabelComponentCache[label.id]
<span className="details">
{labels}
<span className="subject">{subject(thread.subject)}</span>
<span className="snippet">{thread.snippet}</span>
{attachment}
</span>
c4 = new ListTabular.Column
name: "Date"
resolver: (thread) =>
<span className="timestamp">{timestamp(thread.lastMessageReceivedTimestamp)}</span>
c5 = new ListTabular.Column
name: "HoverActions"
resolver: (thread) =>
<div className="inner">
<InjectedComponentSet
key="injected-component-set"
inline={true}
containersRequired={false}
children=
{[
<ThreadTrashQuickAction key="thread-trash-quick-action" thread={thread} />
<ThreadArchiveQuickAction key="thread-archive-quick-action" thread={thread} />
]}
matching={role: "ThreadListQuickAction"}
className="thread-injected-quick-actions"
exposedProps={thread: thread}/>
</div>
cNarrow = new ListTabular.Column
name: "Item"
flex: 1
resolver: (thread) =>
pencil = []
attachment = []
hasDraft = _.find (thread.metadata ? []), (m) -> m.draft
if thread.hasAttachments
attachment = <div className="thread-icon thread-icon-attachment"></div>
if hasDraft
pencil = <RetinaImg name="icon-draft-pencil.png" className="draft-icon" mode={RetinaImg.Mode.ContentPreserve} />
<div>
<div style={display: 'flex'}>
<ThreadListIcon thread={thread} />
<ThreadListParticipants thread={thread} />
{pencil}
<span style={flex:1}></span>
{attachment}
<span className="timestamp">{timestamp(thread.lastMessageReceivedTimestamp)}</span>
</div>
<MailImportantIcon
thread={thread}
showIfAvailableForAnyAccount={true} />
<div className="subject">{subject(thread.subject)}</div>
<div className="snippet">{thread.snippet}</div>
</div>
module.exports =
Narrow: [cNarrow]
Wide: [c1, c2, c3, c4, c5]