diff --git a/internal_packages/thread-list/lib/draft-buttons.cjsx b/internal_packages/thread-list/lib/draft-buttons.cjsx new file mode 100644 index 000000000..1c540d3e1 --- /dev/null +++ b/internal_packages/thread-list/lib/draft-buttons.cjsx @@ -0,0 +1,25 @@ +React = require "react/addons" +classNames = require 'classnames' +DraftListStore = require './draft-list-store' +{RetinaImg} = require 'nylas-component-kit' +{Actions, FocusedContentStore} = require "nylas-exports" + +class DraftDeleteButton extends React.Component + @displayName: 'DraftDeleteButton' + @containerRequired: false + + @propTypes: + selection: React.PropTypes.object.isRequired + + render: -> + + + _destroyDraft: => + Actions.deleteSelection() + +module.exports = {DraftDeleteButton} diff --git a/internal_packages/thread-list/lib/draft-list-store.coffee b/internal_packages/thread-list/lib/draft-list-store.coffee index 26bc7a448..987559f23 100644 --- a/internal_packages/thread-list/lib/draft-list-store.coffee +++ b/internal_packages/thread-list/lib/draft-list-store.coffee @@ -1,13 +1,17 @@ Reflux = require 'reflux' _ = require 'underscore' {Message, + Actions, DatabaseStore, + FocusedContentStore, + DestroyDraftTask, DatabaseView} = require 'nylas-exports' module.exports = DraftListStore = Reflux.createStore init: -> @listenTo DatabaseStore, @_onDataChanged + @listenTo Actions.deleteSelection, @_onDeleteSelection @_view = new DatabaseView Message, matchers: [Message.attributes.draft.equal(true)], @@ -24,3 +28,16 @@ DraftListStore = Reflux.createStore containsDraft = _.some(change.objects, (msg) -> msg.draft) return unless containsDraft @_view.invalidate() + + _onDeleteSelection: -> + selected = @_view.selection.items() + + for item in selected + DatabaseStore.localIdForModel(item).then (localId) => + Actions.queueTask(new DestroyDraftTask(localId)) + # if thread.id is focusedId + # Actions.setFocus(collection: 'thread', item: null) + # if thread.id is keyboardId + # Actions.setCursorPosition(collection: 'thread', item: null) + + @_view.selection.clear() diff --git a/internal_packages/thread-list/lib/draft-selection-bar.cjsx b/internal_packages/thread-list/lib/draft-selection-bar.cjsx index 30f9008dd..1edb1e7f4 100644 --- a/internal_packages/thread-list/lib/draft-selection-bar.cjsx +++ b/internal_packages/thread-list/lib/draft-selection-bar.cjsx @@ -11,5 +11,4 @@ class DraftSelectionBar extends React.Component className="draft-list" collection="draft" /> - module.exports = DraftSelectionBar diff --git a/internal_packages/thread-list/lib/main.cjsx b/internal_packages/thread-list/lib/main.cjsx index 473b1dfcf..e53c43340 100644 --- a/internal_packages/thread-list/lib/main.cjsx +++ b/internal_packages/thread-list/lib/main.cjsx @@ -3,6 +3,7 @@ React = require "react" {ComponentRegistry, WorkspaceStore} = require "nylas-exports" {DownButton, UpButton, ThreadBulkArchiveButton, ThreadBulkStarButton} = require "./thread-buttons" +{DraftDeleteButton} = require "./draft-buttons" ThreadSelectionBar = require './thread-selection-bar' ThreadList = require './thread-list' @@ -41,6 +42,9 @@ module.exports = ComponentRegistry.register ThreadBulkStarButton, role: 'thread:BulkAction' + ComponentRegistry.register DraftDeleteButton, + role: 'draft:BulkAction' + deactivate: -> ComponentRegistry.unregister DraftList ComponentRegistry.unregister DraftSelectionBar @@ -49,3 +53,4 @@ module.exports = ComponentRegistry.unregister ThreadBulkArchiveButton ComponentRegistry.unregister DownButton ComponentRegistry.unregister UpButton + ComponentRegistry.unregister DraftDeleteButton diff --git a/src/flux/actions.coffee b/src/flux/actions.coffee index 7eb836781..0206477be 100644 --- a/src/flux/actions.coffee +++ b/src/flux/actions.coffee @@ -320,6 +320,7 @@ class Actions @archiveAndPrevious: ActionScopeWindow @toggleStarSelection: ActionScopeWindow @toggleStarFocused: ActionScopeWindow + @deleteSelection: ActionScopeWindow ### Public: Updates the search query in the app's main search bar with the provided query text.