fix(sidebar): Correctly update sidebar when a notif is selected

- Clean up AccountSwitcher a bit
This commit is contained in:
Juan Tejada 2016-02-02 10:33:43 -08:00
parent 11429727f9
commit 236c5ddc53
6 changed files with 38 additions and 35 deletions

View file

@ -3,7 +3,6 @@ crypto = require 'crypto'
classNames = require 'classnames'
{Actions} = require 'nylas-exports'
{RetinaImg} = require 'nylas-component-kit'
SidebarActions = require '../sidebar-actions'
ItemTypes = {
@ -28,24 +27,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
@ -60,7 +62,8 @@ class AccountSwitcher extends React.Component
@setState(showing: false)
_onSwitchAccount: (item) =>
SidebarActions.focusAccounts(item.accounts)
Actions.focusDefaultMailboxPerspectiveForAccounts(item.accounts)
Actions.focusSidebarAccounts(item.accounts)
@setState(showing: false)
_onManageAccounts: =>
@ -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}

View file

@ -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

View file

@ -1,12 +1,12 @@
_ = require 'underscore'
{AccountStore, MenuHelpers} = require 'nylas-exports'
SidebarActions = require './sidebar-actions'
{AccountStore, Actions, MenuHelpers} = require 'nylas-exports'
class SidebarCommands
@_focusAccounts: (accounts) ->
SidebarActions.focusAccounts(accounts)
Actions.focusDefaultMailboxPerspectiveForAccounts(accounts)
Actions.focusSidebarAccounts(accounts)
NylasEnv.show() unless NylasEnv.isVisible()
@_registerCommands: ->

View file

@ -8,7 +8,6 @@ _ = require 'underscore'
CategoryStore} = require 'nylas-exports'
SidebarSection = require './sidebar-section'
SidebarActions = require './sidebar-actions'
Sections = {
"Standard",
@ -38,7 +37,7 @@ class SidebarStore extends NylasStore
@_sections[Sections.User]
_registerListeners: ->
@listenTo SidebarActions.focusAccounts, @_onAccountsFocused
@listenTo Actions.focusSidebarAccounts, @_onAccountsFocused
@listenTo AccountStore, @_onAccountsChanged
@listenTo FocusedPerspectiveStore, @_updateSections
@listenTo WorkspaceStore, @_updateSections
@ -56,7 +55,6 @@ class SidebarStore extends NylasStore
return
_onAccountsFocused: (accounts) =>
Actions.focusDefaultMailboxPerspectiveForAccounts(accounts)
@_focusedAccounts = accounts
@_updateSections()

View file

@ -62,8 +62,10 @@ module.exports =
return unless desiredCategory
unless desiredCategory.id in _.pluck(currentCategories, 'id')
filter = MailboxPerspective.forCategory(desiredCategory)
Actions.focusMailboxPerspective(filter)
perspective = MailboxPerspective.forCategory(desiredCategory)
accounts = perspective.accountIds.map (id) -> AccountStore.accountForId(id)
Actions.focusMailboxPerspective(perspective)
Actions.focusSidebarAccounts(accounts)
Actions.setFocus(collection: 'thread', item: thread)
_notifyMessages: ->

View file

@ -244,6 +244,17 @@ class Actions
###
@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
thread view, this action toggles whether it's full content or snippet is shown.