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: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')

View file

@ -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 ""
<KeyCommandsRegion globalHandlers={@_globalHandlers()}>
<div className="mail-important-icon #{activeClassname}"
title={if isImportant then "Mark as unimportant" else "Mark as important"}
onClick={@_onToggleImportant}></div>
</KeyCommandsRegion>
_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)

View file

@ -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) =>