diff --git a/internal_packages/account-sidebar/lib/components/account-switcher.cjsx b/internal_packages/account-sidebar/lib/components/account-switcher.cjsx index 2b470d926..d55385c7a 100644 --- a/internal_packages/account-sidebar/lib/components/account-switcher.cjsx +++ b/internal_packages/account-sidebar/lib/components/account-switcher.cjsx @@ -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)
@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