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
This commit is contained in:
Juan Tejada 2015-12-07 12:05:40 -08:00
parent 7f87ffbe17
commit 7a5be0e7a7
3 changed files with 34 additions and 23 deletions

View file

@ -193,6 +193,8 @@ class ThreadList extends React.Component
'application:archive-item': @_onArchiveItem 'application:archive-item': @_onArchiveItem
'application:delete-item': @_onDeleteItem 'application:delete-item': @_onDeleteItem
'application:star-item': @_onStarItem 'application:star-item': @_onStarItem
'application:mark-important': @_onSetImportantItem
'application:mark-unimportant': @_onSetUnimportantItem
'application:remove-and-previous': => 'application:remove-and-previous': =>
@_shift(offset: 1, afterRunning: @_onRemoveFromView) @_shift(offset: 1, afterRunning: @_onRemoveFromView)
'application:remove-and-next': => 'application:remove-and-next': =>
@ -282,6 +284,24 @@ class ThreadList extends React.Component
task = TaskFactory.taskForInvertingStarred({threads}) task = TaskFactory.taskForInvertingStarred({threads})
Actions.queueTask(task) 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: => _onRemoveFromView: =>
threads = @_threadsForKeyboardAction() threads = @_threadsForKeyboardAction()
backspaceDelete = NylasEnv.config.get('core.reading.backspaceDelete') backspaceDelete = NylasEnv.config.get('core.reading.backspaceDelete')

View file

@ -3,10 +3,9 @@ React = require 'react'
{Actions, {Actions,
Utils, Utils,
Thread, Thread,
ChangeLabelsTask, TaskFactory,
CategoryStore, CategoryStore,
AccountStore} = require 'nylas-exports' AccountStore} = require 'nylas-exports'
{KeyCommandsRegion} = require 'nylas-component-kit'
class MailImportantIcon extends React.Component class MailImportantIcon extends React.Component
@displayName: 'MailImportantIcon' @displayName: 'MailImportantIcon'
@ -17,10 +16,10 @@ class MailImportantIcon extends React.Component
@state = @getState() @state = @getState()
getState: => getState: =>
showing: AccountStore.current()?.usesImportantFlag() and NylasEnv.config.get('core.showImportant') showing: AccountStore.current()?.usesImportantFlag() and NylasEnv.config.get('core.workspace.showImportant')
componentDidMount: => componentDidMount: =>
@subscription = NylasEnv.config.observe 'core.showImportant', => @subscription = NylasEnv.config.observe 'core.workspace.showImportant', =>
@setState(@getState()) @setState(@getState())
componentWillUnmount: => componentWillUnmount: =>
@ -39,27 +38,19 @@ class MailImportantIcon extends React.Component
isImportant = _.findWhere(@props.thread.labels, {id: importantId})? isImportant = _.findWhere(@props.thread.labels, {id: importantId})?
activeClassname = if isImportant then "active" else "" activeClassname = if isImportant then "active" else ""
<KeyCommandsRegion globalHandlers={@_globalHandlers()}>
<div className="mail-important-icon #{activeClassname}" <div className="mail-important-icon #{activeClassname}"
title={if isImportant then "Mark as unimportant" else "Mark as important"} title={if isImportant then "Mark as unimportant" else "Mark as important"}
onClick={@_onToggleImportant}></div> onClick={@_onToggleImportant}></div>
</KeyCommandsRegion>
_globalHandlers: =>
'application:mark-as-important': (e) => @_setImportant(e, true)
'application:mark-as-unimportant': (e) => @_setImportant(e, false)
_onToggleImportant: (event) => _onToggleImportant: (event) =>
isImportant = _.findWhere(@props.thread.labels, {id: importantLabel.id})? category = CategoryStore.getStandardCategory('important')
@_setImportant(event, !isImportant) isImportant = _.findWhere(@props.thread.labels, {id: category.id})?
threads = [@props.thread]
_setImportant: (event, important) => if !isImportant
importantLabel = CategoryStore.getStandardCategory('important') task = TaskFactory.taskForApplyingCategory({threads, category})
if important
task = new ChangeLabelsTask(thread: @props.thread, labelsToAdd: [importantLabel], labelsToRemove: [])
else else
task = new ChangeLabelsTask(thread: @props.thread, labelsToRemove: [importantLabel], labelsToAdd: []) task = TaskFactory.taskForRemovingCategory({threads, category})
Actions.queueTask(task) Actions.queueTask(task)

View file

@ -15,7 +15,7 @@ class CategoryStore extends NylasStore
@listenTo DatabaseStore, @_onDBChanged @listenTo DatabaseStore, @_onDBChanged
@listenTo AccountStore, @_refreshCacheFromDB @listenTo AccountStore, @_refreshCacheFromDB
NylasEnv.config.observe 'core.showImportant', => @_refreshCacheFromDB() NylasEnv.config.observe 'core.workspace.showImportant', => @_refreshCacheFromDB()
@_refreshCacheFromDB() @_refreshCacheFromDB()
@ -173,7 +173,7 @@ class CategoryStore extends NylasStore
for key, val of @_categoryCache for key, val of @_categoryCache
byStandardName[val.name] = val byStandardName[val.name] = val
if not NylasEnv.config.get('core.showImportant') if not NylasEnv.config.get('core.workspace.showImportant')
delete byStandardName['important'] delete byStandardName['important']
@_standardCategories = _.compact @StandardCategoryNames.map (name) => @_standardCategories = _.compact @StandardCategoryNames.map (name) =>