mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-11 10:12:00 +08:00
feat(shortcuts): Add listeners for unread/important keyboard shortcuts
Summary: - Adds KeyCommandRegions to hook up missing listeners for marking as unread and important keyboard shortcuts - Updates specs Test Plan: - All tests pass Reviewers: evan, bengotow Reviewed By: bengotow Differential Revision: https://phab.nylas.com/D2300
This commit is contained in:
parent
e356fd378d
commit
24978b2a4b
3 changed files with 38 additions and 18 deletions
|
@ -1,6 +1,6 @@
|
||||||
React = require 'react'
|
React = require 'react'
|
||||||
{Actions, FocusedContentStore, ChangeUnreadTask} = require 'nylas-exports'
|
{Actions, FocusedContentStore, ChangeUnreadTask} = require 'nylas-exports'
|
||||||
{RetinaImg} = require 'nylas-component-kit'
|
{RetinaImg, KeyCommandsRegion} = require 'nylas-component-kit'
|
||||||
|
|
||||||
class ThreadToggleUnreadButton extends React.Component
|
class ThreadToggleUnreadButton extends React.Component
|
||||||
@displayName: "ThreadToggleUnreadButton"
|
@displayName: "ThreadToggleUnreadButton"
|
||||||
|
@ -9,6 +9,7 @@ class ThreadToggleUnreadButton extends React.Component
|
||||||
render: =>
|
render: =>
|
||||||
fragment = if @props.thread?.unread then "read" else "unread"
|
fragment = if @props.thread?.unread then "read" else "unread"
|
||||||
|
|
||||||
|
<KeyCommandsRegion globalHandlers={@_globalHandlers()} >
|
||||||
<button className="btn btn-toolbar"
|
<button className="btn btn-toolbar"
|
||||||
style={order: -105}
|
style={order: -105}
|
||||||
title="Mark as #{fragment}"
|
title="Mark as #{fragment}"
|
||||||
|
@ -16,11 +17,19 @@ class ThreadToggleUnreadButton extends React.Component
|
||||||
<RetinaImg name="toolbar-markas#{fragment}.png"
|
<RetinaImg name="toolbar-markas#{fragment}.png"
|
||||||
mode={RetinaImg.Mode.ContentIsMask} />
|
mode={RetinaImg.Mode.ContentIsMask} />
|
||||||
</button>
|
</button>
|
||||||
|
</KeyCommandsRegion>
|
||||||
|
|
||||||
|
_globalHandlers: =>
|
||||||
|
'application:mark-as-unread': (e) => @_setUnread(e, true)
|
||||||
|
'application:mark-as-read': (e) => @_setUnread(e, false)
|
||||||
|
|
||||||
_onClick: (e) =>
|
_onClick: (e) =>
|
||||||
|
@_setUnread(e, !@props.thread.unread)
|
||||||
|
|
||||||
|
_setUnread: (e, unread)=>
|
||||||
task = new ChangeUnreadTask
|
task = new ChangeUnreadTask
|
||||||
thread: @props.thread
|
thread: @props.thread
|
||||||
unread: !@props.thread.unread
|
unread: unread
|
||||||
Actions.queueTask(task)
|
Actions.queueTask(task)
|
||||||
Actions.popSheet()
|
Actions.popSheet()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
|
|
@ -49,7 +49,7 @@ describe "MessageToolbarItem marking as unread", ->
|
||||||
|
|
||||||
it "queues a task to change unread status to true", ->
|
it "queues a task to change unread status to true", ->
|
||||||
spyOn Actions, "queueTask"
|
spyOn Actions, "queueTask"
|
||||||
ReactTestUtils.Simulate.click React.findDOMNode(markUnreadBtn)
|
ReactTestUtils.Simulate.click React.findDOMNode(markUnreadBtn).childNodes[0]
|
||||||
|
|
||||||
changeUnreadTask = Actions.queueTask.calls[0].args[0]
|
changeUnreadTask = Actions.queueTask.calls[0].args[0]
|
||||||
expect(changeUnreadTask instanceof ChangeUnreadTask).toBe true
|
expect(changeUnreadTask instanceof ChangeUnreadTask).toBe true
|
||||||
|
@ -58,6 +58,7 @@ describe "MessageToolbarItem marking as unread", ->
|
||||||
|
|
||||||
it "returns to the thread list", ->
|
it "returns to the thread list", ->
|
||||||
spyOn Actions, "popSheet"
|
spyOn Actions, "popSheet"
|
||||||
ReactTestUtils.Simulate.click React.findDOMNode(markUnreadBtn)
|
ReactTestUtils.Simulate.click React.findDOMNode(markUnreadBtn).childNodes[0]
|
||||||
|
|
||||||
expect(Actions.popSheet).toHaveBeenCalled()
|
expect(Actions.popSheet).toHaveBeenCalled()
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ React = require 'react'
|
||||||
ChangeLabelsTask,
|
ChangeLabelsTask,
|
||||||
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'
|
||||||
|
@ -38,18 +39,27 @@ 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) =>
|
||||||
importantLabel = CategoryStore.getStandardCategory('important')
|
|
||||||
isImportant = _.findWhere(@props.thread.labels, {id: importantLabel.id})?
|
isImportant = _.findWhere(@props.thread.labels, {id: importantLabel.id})?
|
||||||
|
@_setImportant(event, !isImportant)
|
||||||
|
|
||||||
if isImportant
|
_setImportant: (event, important) =>
|
||||||
task = new ChangeLabelsTask(thread: @props.thread, labelsToRemove: [importantLabel], labelsToAdd: [])
|
importantLabel = CategoryStore.getStandardCategory('important')
|
||||||
else
|
|
||||||
|
if important
|
||||||
task = new ChangeLabelsTask(thread: @props.thread, labelsToAdd: [importantLabel], labelsToRemove: [])
|
task = new ChangeLabelsTask(thread: @props.thread, labelsToAdd: [importantLabel], labelsToRemove: [])
|
||||||
|
else
|
||||||
|
task = new ChangeLabelsTask(thread: @props.thread, labelsToRemove: [importantLabel], labelsToAdd: [])
|
||||||
|
|
||||||
Actions.queueTask(task)
|
Actions.queueTask(task)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue