mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-21 07:46:06 +08:00
fix(sidebar): Correctly update sidebar when a notif is selected
- Clean up AccountSwitcher a bit
This commit is contained in:
parent
11429727f9
commit
236c5ddc53
|
@ -3,7 +3,6 @@ crypto = require 'crypto'
|
||||||
classNames = require 'classnames'
|
classNames = require 'classnames'
|
||||||
{Actions} = require 'nylas-exports'
|
{Actions} = require 'nylas-exports'
|
||||||
{RetinaImg} = require 'nylas-component-kit'
|
{RetinaImg} = require 'nylas-component-kit'
|
||||||
SidebarActions = require '../sidebar-actions'
|
|
||||||
|
|
||||||
|
|
||||||
ItemTypes = {
|
ItemTypes = {
|
||||||
|
@ -28,24 +27,27 @@ class AccountSwitcher extends React.Component
|
||||||
|
|
||||||
# Helpers
|
# Helpers
|
||||||
|
|
||||||
_makeItem: (account = {}) =>
|
_makeAccountItem: (account) =>
|
||||||
{id, label, emailAddress, provider} = account
|
{id, label, emailAddress, provider} = account
|
||||||
id ?= ItemTypes.Unified
|
email = emailAddress
|
||||||
label ?= "All Accounts"
|
iconName = provider
|
||||||
email = emailAddress ? ""
|
accounts = [account]
|
||||||
iconName = provider ? 'unified'
|
|
||||||
accounts = if id is ItemTypes.Unified
|
|
||||||
@props.accounts
|
|
||||||
else
|
|
||||||
[account]
|
|
||||||
|
|
||||||
return {id, label, email, iconName, accounts}
|
return {id, label, email, iconName, accounts}
|
||||||
|
|
||||||
|
_makeUnifiedItem: =>
|
||||||
|
id = ItemTypes.Unified
|
||||||
|
label = "All Accounts"
|
||||||
|
email = ""
|
||||||
|
iconName = 'unified'
|
||||||
|
accounts = @props.accounts
|
||||||
|
return {id, label, email, iconName, accounts}
|
||||||
|
|
||||||
|
|
||||||
_selectedItem: =>
|
_selectedItem: =>
|
||||||
if @props.focusedAccounts.length > 1
|
if @props.focusedAccounts.length > 1
|
||||||
@_makeItem()
|
@_makeUnifiedItem()
|
||||||
else
|
else
|
||||||
@_makeItem(@props.focusedAccounts[0])
|
@_makeAccountItem(@props.focusedAccounts[0])
|
||||||
|
|
||||||
_toggleDropdown: =>
|
_toggleDropdown: =>
|
||||||
@setState showing: !@state.showing
|
@setState showing: !@state.showing
|
||||||
|
@ -60,7 +62,8 @@ class AccountSwitcher extends React.Component
|
||||||
@setState(showing: false)
|
@setState(showing: false)
|
||||||
|
|
||||||
_onSwitchAccount: (item) =>
|
_onSwitchAccount: (item) =>
|
||||||
SidebarActions.focusAccounts(item.accounts)
|
Actions.focusDefaultMailboxPerspectiveForAccounts(item.accounts)
|
||||||
|
Actions.focusSidebarAccounts(item.accounts)
|
||||||
@setState(showing: false)
|
@setState(showing: false)
|
||||||
|
|
||||||
_onManageAccounts: =>
|
_onManageAccounts: =>
|
||||||
|
@ -140,9 +143,9 @@ class AccountSwitcher extends React.Component
|
||||||
classnames += " open" if @state.showing
|
classnames += " open" if @state.showing
|
||||||
selected = @_selectedItem()
|
selected = @_selectedItem()
|
||||||
if @props.accounts.length is 1
|
if @props.accounts.length is 1
|
||||||
items = @props.accounts.map(@_makeItem)
|
items = @props.accounts.map(@_makeAccountItem)
|
||||||
else
|
else
|
||||||
items = [@_makeItem()].concat @props.accounts.map(@_makeItem)
|
items = [@_makeUnifiedItem()].concat @props.accounts.map(@_makeAccountItem)
|
||||||
|
|
||||||
<div
|
<div
|
||||||
className={classnames}
|
className={classnames}
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
Reflux = require 'reflux'
|
|
||||||
|
|
||||||
Actions = [
|
|
||||||
'focusAccounts'
|
|
||||||
]
|
|
||||||
|
|
||||||
for idx in Actions
|
|
||||||
Actions[idx] = Reflux.createAction(Actions[idx])
|
|
||||||
Actions[idx].sync = true
|
|
||||||
|
|
||||||
module.exports = Actions
|
|
|
@ -1,12 +1,12 @@
|
||||||
_ = require 'underscore'
|
_ = require 'underscore'
|
||||||
{AccountStore, MenuHelpers} = require 'nylas-exports'
|
{AccountStore, Actions, MenuHelpers} = require 'nylas-exports'
|
||||||
SidebarActions = require './sidebar-actions'
|
|
||||||
|
|
||||||
|
|
||||||
class SidebarCommands
|
class SidebarCommands
|
||||||
|
|
||||||
@_focusAccounts: (accounts) ->
|
@_focusAccounts: (accounts) ->
|
||||||
SidebarActions.focusAccounts(accounts)
|
Actions.focusDefaultMailboxPerspectiveForAccounts(accounts)
|
||||||
|
Actions.focusSidebarAccounts(accounts)
|
||||||
NylasEnv.show() unless NylasEnv.isVisible()
|
NylasEnv.show() unless NylasEnv.isVisible()
|
||||||
|
|
||||||
@_registerCommands: ->
|
@_registerCommands: ->
|
||||||
|
|
|
@ -8,7 +8,6 @@ _ = require 'underscore'
|
||||||
CategoryStore} = require 'nylas-exports'
|
CategoryStore} = require 'nylas-exports'
|
||||||
|
|
||||||
SidebarSection = require './sidebar-section'
|
SidebarSection = require './sidebar-section'
|
||||||
SidebarActions = require './sidebar-actions'
|
|
||||||
|
|
||||||
Sections = {
|
Sections = {
|
||||||
"Standard",
|
"Standard",
|
||||||
|
@ -38,7 +37,7 @@ class SidebarStore extends NylasStore
|
||||||
@_sections[Sections.User]
|
@_sections[Sections.User]
|
||||||
|
|
||||||
_registerListeners: ->
|
_registerListeners: ->
|
||||||
@listenTo SidebarActions.focusAccounts, @_onAccountsFocused
|
@listenTo Actions.focusSidebarAccounts, @_onAccountsFocused
|
||||||
@listenTo AccountStore, @_onAccountsChanged
|
@listenTo AccountStore, @_onAccountsChanged
|
||||||
@listenTo FocusedPerspectiveStore, @_updateSections
|
@listenTo FocusedPerspectiveStore, @_updateSections
|
||||||
@listenTo WorkspaceStore, @_updateSections
|
@listenTo WorkspaceStore, @_updateSections
|
||||||
|
@ -56,7 +55,6 @@ class SidebarStore extends NylasStore
|
||||||
return
|
return
|
||||||
|
|
||||||
_onAccountsFocused: (accounts) =>
|
_onAccountsFocused: (accounts) =>
|
||||||
Actions.focusDefaultMailboxPerspectiveForAccounts(accounts)
|
|
||||||
@_focusedAccounts = accounts
|
@_focusedAccounts = accounts
|
||||||
@_updateSections()
|
@_updateSections()
|
||||||
|
|
||||||
|
|
|
@ -62,8 +62,10 @@ module.exports =
|
||||||
|
|
||||||
return unless desiredCategory
|
return unless desiredCategory
|
||||||
unless desiredCategory.id in _.pluck(currentCategories, 'id')
|
unless desiredCategory.id in _.pluck(currentCategories, 'id')
|
||||||
filter = MailboxPerspective.forCategory(desiredCategory)
|
perspective = MailboxPerspective.forCategory(desiredCategory)
|
||||||
Actions.focusMailboxPerspective(filter)
|
accounts = perspective.accountIds.map (id) -> AccountStore.accountForId(id)
|
||||||
|
Actions.focusMailboxPerspective(perspective)
|
||||||
|
Actions.focusSidebarAccounts(accounts)
|
||||||
Actions.setFocus(collection: 'thread', item: thread)
|
Actions.setFocus(collection: 'thread', item: thread)
|
||||||
|
|
||||||
_notifyMessages: ->
|
_notifyMessages: ->
|
||||||
|
|
|
@ -244,6 +244,17 @@ class Actions
|
||||||
###
|
###
|
||||||
@focusDefaultMailboxPerspectiveForAccounts: ActionScopeWindow
|
@focusDefaultMailboxPerspectiveForAccounts: ActionScopeWindow
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
Public: Focus a set of accounts on the sidebar. This means that the source list
|
||||||
|
the sidebar will be updated to reflect the set of selected accounts, i.e. unified
|
||||||
|
or single
|
||||||
|
|
||||||
|
*Scope: Window*
|
||||||
|
###
|
||||||
|
@focusSidebarAccounts: ActionScopeWindow
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
Public: If the message with the provided id is currently beign displayed in the
|
Public: If the message with the provided id is currently beign displayed in the
|
||||||
thread view, this action toggles whether it's full content or snippet is shown.
|
thread view, this action toggles whether it's full content or snippet is shown.
|
||||||
|
|
Loading…
Reference in a new issue