From 7a5be0e7a75aececca140d3d92eab35806fb1d37 Mon Sep 17 00:00:00 2001 From: Juan Tejada Date: Mon, 7 Dec 2015 12:05:40 -0800 Subject: [PATCH] fix(important): Fixes keymap handlers for mark as important/unimportant - Updates to bind handlers inside thread list - Fixes typo in event name - Updates config path for showImportant --- .../thread-list/lib/thread-list.cjsx | 20 +++++++++++ src/components/mail-important-icon.cjsx | 33 +++++++------------ src/flux/stores/category-store.coffee | 4 +-- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/internal_packages/thread-list/lib/thread-list.cjsx b/internal_packages/thread-list/lib/thread-list.cjsx index 80c6656ec..c5e290549 100644 --- a/internal_packages/thread-list/lib/thread-list.cjsx +++ b/internal_packages/thread-list/lib/thread-list.cjsx @@ -193,6 +193,8 @@ class ThreadList extends React.Component 'application:archive-item': @_onArchiveItem 'application:delete-item': @_onDeleteItem 'application:star-item': @_onStarItem + 'application:mark-important': @_onSetImportantItem + 'application:mark-unimportant': @_onSetUnimportantItem 'application:remove-and-previous': => @_shift(offset: 1, afterRunning: @_onRemoveFromView) 'application:remove-and-next': => @@ -282,6 +284,24 @@ class ThreadList extends React.Component task = TaskFactory.taskForInvertingStarred({threads}) Actions.queueTask(task) + _onSetImportantItem: => + @_setImportant(true) + + _onSetUnimportantItem: => + @_setImportant(false) + + _setImportant: (important) => + threads = @_threadsForKeyboardAction() + return unless threads + return unless AccountStore.current()?.usesImportantFlag() + category = CategoryStore.getStandardCategory('important') + if important + task = TaskFactory.taskForApplyingCategory({threads, category}) + else + task = TaskFactory.taskForRemovingCategory({threads, category}) + + Actions.queueTask(task) + _onRemoveFromView: => threads = @_threadsForKeyboardAction() backspaceDelete = NylasEnv.config.get('core.reading.backspaceDelete') diff --git a/src/components/mail-important-icon.cjsx b/src/components/mail-important-icon.cjsx index 43935ce85..9a541b243 100644 --- a/src/components/mail-important-icon.cjsx +++ b/src/components/mail-important-icon.cjsx @@ -3,10 +3,9 @@ React = require 'react' {Actions, Utils, Thread, - ChangeLabelsTask, + TaskFactory, CategoryStore, AccountStore} = require 'nylas-exports' -{KeyCommandsRegion} = require 'nylas-component-kit' class MailImportantIcon extends React.Component @displayName: 'MailImportantIcon' @@ -17,10 +16,10 @@ class MailImportantIcon extends React.Component @state = @getState() getState: => - showing: AccountStore.current()?.usesImportantFlag() and NylasEnv.config.get('core.showImportant') + showing: AccountStore.current()?.usesImportantFlag() and NylasEnv.config.get('core.workspace.showImportant') componentDidMount: => - @subscription = NylasEnv.config.observe 'core.showImportant', => + @subscription = NylasEnv.config.observe 'core.workspace.showImportant', => @setState(@getState()) componentWillUnmount: => @@ -39,27 +38,19 @@ class MailImportantIcon extends React.Component isImportant = _.findWhere(@props.thread.labels, {id: importantId})? activeClassname = if isImportant then "active" else "" - -
-
- - _globalHandlers: => - 'application:mark-as-important': (e) => @_setImportant(e, true) - 'application:mark-as-unimportant': (e) => @_setImportant(e, false) +
_onToggleImportant: (event) => - isImportant = _.findWhere(@props.thread.labels, {id: importantLabel.id})? - @_setImportant(event, !isImportant) + category = CategoryStore.getStandardCategory('important') + isImportant = _.findWhere(@props.thread.labels, {id: category.id})? + threads = [@props.thread] - _setImportant: (event, important) => - importantLabel = CategoryStore.getStandardCategory('important') - - if important - task = new ChangeLabelsTask(thread: @props.thread, labelsToAdd: [importantLabel], labelsToRemove: []) + if !isImportant + task = TaskFactory.taskForApplyingCategory({threads, category}) else - task = new ChangeLabelsTask(thread: @props.thread, labelsToRemove: [importantLabel], labelsToAdd: []) + task = TaskFactory.taskForRemovingCategory({threads, category}) Actions.queueTask(task) diff --git a/src/flux/stores/category-store.coffee b/src/flux/stores/category-store.coffee index 3ad530679..8fba60b95 100644 --- a/src/flux/stores/category-store.coffee +++ b/src/flux/stores/category-store.coffee @@ -15,7 +15,7 @@ class CategoryStore extends NylasStore @listenTo DatabaseStore, @_onDBChanged @listenTo AccountStore, @_refreshCacheFromDB - NylasEnv.config.observe 'core.showImportant', => @_refreshCacheFromDB() + NylasEnv.config.observe 'core.workspace.showImportant', => @_refreshCacheFromDB() @_refreshCacheFromDB() @@ -173,7 +173,7 @@ class CategoryStore extends NylasStore for key, val of @_categoryCache byStandardName[val.name] = val - if not NylasEnv.config.get('core.showImportant') + if not NylasEnv.config.get('core.workspace.showImportant') delete byStandardName['important'] @_standardCategories = _.compact @StandardCategoryNames.map (name) =>