Mailspring/internal_packages/draft-list/lib/draft-list-store.coffee
Juan Tejada e83bf2bbec feat(selection): Add new display for selection count + update toolbar
Summary:
- New behavior is that the in split mode, you will perform actions on
  the selection via the MessageListToolbar (the toolbar positioned above
  the message list)
- Refactored and moved around a bunch of code to achieve this:
  - Mostly renaming stuff and moving stuff around and removing some
    duplication
  - Update naming of toolbar role to a single role, and update relevant code
  - Converted and refactored a bunch of code into ES6, specifically to reuse the code for the ThreadActionsToolbar at the 2 locations
  - Deprecated MultiselectActionBar in favor of MultiselectToolbar
  - Deprecated old roles
- Punted the animation for the stackable cards in the selection display for now.
- #370

Test Plan: - Manual and unit tests

Reviewers: evan, drew, bengotow

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D2756
2016-03-21 12:20:11 -07:00

71 lines
2.2 KiB
CoffeeScript

NylasStore = require 'nylas-store'
Rx = require 'rx-lite'
_ = require 'underscore'
{Message,
OutboxStore,
MutableQueryResultSet,
MutableQuerySubscription,
ObservableListDataSource,
FocusedPerspectiveStore,
DatabaseStore} = require 'nylas-exports'
{ListTabular} = require 'nylas-component-kit'
class DraftListStore extends NylasStore
constructor: ->
@listenTo FocusedPerspectiveStore, @_onPerspectiveChanged
@_createListDataSource()
dataSource: =>
@_dataSource
selectionObservable: =>
return Rx.Observable.fromListSelection(@)
# Inbound Events
_onPerspectiveChanged: =>
@_createListDataSource()
# Internal
_createListDataSource: =>
mailboxPerspective = FocusedPerspectiveStore.current()
if mailboxPerspective.drafts
query = DatabaseStore.findAll(Message)
.include(Message.attributes.body)
.order(Message.attributes.date.descending())
.where(draft: true, accountId: mailboxPerspective.accountIds)
.page(0, 1)
subscription = new MutableQuerySubscription(query, {asResultSet: true})
$resultSet = Rx.Observable.fromNamedQuerySubscription('draft-list', subscription)
$resultSet = Rx.Observable.combineLatest [
$resultSet,
Rx.Observable.fromStore(OutboxStore)
], (resultSet, outbox) =>
# Generate a new result set that includes additional information on
# the draft objects. This is similar to what we do in the thread-list,
# where we set thread.metadata to the message array.
resultSetWithTasks = new MutableQueryResultSet(resultSet)
mailboxPerspective.accountIds.forEach (aid) =>
OutboxStore.itemsForAccount(aid).forEach (task) =>
draft = resultSet.modelWithId(task.draftClientId)
if draft
draft = draft.clone()
draft.uploadTaskId = task.id
draft.uploadProgress = task.progress
resultSetWithTasks.replaceModel(draft)
return resultSetWithTasks.immutableClone()
@_dataSource = new ObservableListDataSource($resultSet, subscription.replaceRange)
else
@_dataSource = new ListTabular.DataSource.Empty()
@trigger(@)
module.exports = new DraftListStore()