mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-12-29 11:52:34 +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
|
||||
|
||||
_makeItem: (account = {}) =>
|
||||
_makeAccountItem: (account) =>
|
||||
{id, label, emailAddress, provider} = account
|
||||
id ?= ItemTypes.Unified
|
||||
label ?= "All Accounts"
|
||||
email = emailAddress ? ""
|
||||
iconName = provider ? 'unified'
|
||||
accounts = if id is ItemTypes.Unified
|
||||
@props.accounts
|
||||
else
|
||||
[account]
|
||||
|
||||
email = emailAddress
|
||||
iconName = provider
|
||||
accounts = [account]
|
||||
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: =>
|
||||
if @props.focusedAccounts.length > 1
|
||||
@_makeItem()
|
||||
@_makeUnifiedItem()
|
||||
else
|
||||
@_makeItem(@props.focusedAccounts[0])
|
||||
@_makeAccountItem(@props.focusedAccounts[0])
|
||||
|
||||
_toggleDropdown: =>
|
||||
@setState showing: !@state.showing
|
||||
|
@ -140,9 +143,9 @@ class AccountSwitcher extends React.Component
|
|||
classnames += " open" if @state.showing
|
||||
selected = @_selectedItem()
|
||||
if @props.accounts.length is 1
|
||||
items = @props.accounts.map(@_makeItem)
|
||||
items = @props.accounts.map(@_makeAccountItem)
|
||||
else
|
||||
items = [@_makeItem()].concat @props.accounts.map(@_makeItem)
|
||||
items = [@_makeUnifiedItem()].concat @props.accounts.map(@_makeAccountItem)
|
||||
|
||||
<div
|
||||
className={classnames}
|
||||
|
|
|
@ -40,7 +40,7 @@ class SidebarStore extends NylasStore
|
|||
_registerListeners: ->
|
||||
@listenTo SidebarActions.focusAccounts, @_onAccountsFocused
|
||||
@listenTo AccountStore, @_onAccountsChanged
|
||||
@listenTo FocusedPerspectiveStore, @_updateSections
|
||||
@listenTo FocusedPerspectiveStore, @_onFocusedPerspectiveChanged
|
||||
@listenTo WorkspaceStore, @_updateSections
|
||||
@listenTo ThreadCountsStore, @_updateSections
|
||||
@listenTo CategoryStore, @_updateSections
|
||||
|
@ -64,6 +64,14 @@ class SidebarStore extends NylasStore
|
|||
@_focusedAccounts = AccountStore.accounts()
|
||||
@_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: =>
|
||||
accounts = @_focusedAccounts
|
||||
multiAccount = accounts.length > 1
|
||||
|
|
Loading…
Reference in a new issue