mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-01 13:14:16 +08:00
fix(sidebar):Correctly update sidebar by listening to FocusedPerspective
- Clean up AccountSwitcher a bit
This commit is contained in:
parent
bdabd1de62
commit
460956bc37
2 changed files with 26 additions and 15 deletions
|
@ -28,24 +28,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
|
||||||
|
@ -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}
|
||||||
|
|
|
@ -40,7 +40,7 @@ class SidebarStore extends NylasStore
|
||||||
_registerListeners: ->
|
_registerListeners: ->
|
||||||
@listenTo SidebarActions.focusAccounts, @_onAccountsFocused
|
@listenTo SidebarActions.focusAccounts, @_onAccountsFocused
|
||||||
@listenTo AccountStore, @_onAccountsChanged
|
@listenTo AccountStore, @_onAccountsChanged
|
||||||
@listenTo FocusedPerspectiveStore, @_updateSections
|
@listenTo FocusedPerspectiveStore, @_onFocusedPerspectiveChanged
|
||||||
@listenTo WorkspaceStore, @_updateSections
|
@listenTo WorkspaceStore, @_updateSections
|
||||||
@listenTo ThreadCountsStore, @_updateSections
|
@listenTo ThreadCountsStore, @_updateSections
|
||||||
@listenTo CategoryStore, @_updateSections
|
@listenTo CategoryStore, @_updateSections
|
||||||
|
@ -64,6 +64,14 @@ class SidebarStore extends NylasStore
|
||||||
@_focusedAccounts = AccountStore.accounts()
|
@_focusedAccounts = AccountStore.accounts()
|
||||||
@_updateSections()
|
@_updateSections()
|
||||||
|
|
||||||
|
_onFocusedPerspectiveChanged: =>
|
||||||
|
currentIds = _.pluck(@_focusedAccounts, 'id')
|
||||||
|
newIds = FocusedPerspectiveStore.current().accountIds
|
||||||
|
newIdsNotInCurrent = _.difference(newIds, currentIds).length > 0
|
||||||
|
if newIdsNotInCurrent
|
||||||
|
@_focusedAccounts = newIds.map (id) -> AccountStore.accountForId(id)
|
||||||
|
@_updateSections()
|
||||||
|
|
||||||
_updateSections: =>
|
_updateSections: =>
|
||||||
accounts = @_focusedAccounts
|
accounts = @_focusedAccounts
|
||||||
multiAccount = accounts.length > 1
|
multiAccount = accounts.length > 1
|
||||||
|
|
Loading…
Reference in a new issue