mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 05:41:05 +08:00
e3b8803250
- Ensures that it displays the correct set of sidebar items even when the perspective changes - Also sets up hotkeys to switch currently focused accounts
78 lines
2 KiB
CoffeeScript
78 lines
2 KiB
CoffeeScript
NylasStore = require 'nylas-store'
|
|
_ = require 'underscore'
|
|
{Actions,
|
|
AccountStore,
|
|
ThreadCountsStore,
|
|
DraftCountStore,
|
|
WorkspaceStore,
|
|
FocusedPerspectiveStore,
|
|
CategoryStore} = require 'nylas-exports'
|
|
|
|
SidebarSection = require './sidebar-section'
|
|
SidebarActions = require './sidebar-actions'
|
|
|
|
Sections = {
|
|
"Standard",
|
|
"User"
|
|
}
|
|
|
|
class SidebarStore extends NylasStore
|
|
|
|
constructor: ->
|
|
@_sections = {}
|
|
@_sections[Sections.Standard] = {}
|
|
@_sections[Sections.User] = []
|
|
@_focusedAccounts = @accounts()
|
|
@_registerListeners()
|
|
@_updateSections()
|
|
|
|
accounts: ->
|
|
AccountStore.accounts()
|
|
|
|
focusedAccounts: ->
|
|
@_focusedAccounts
|
|
|
|
standardSection: ->
|
|
@_sections[Sections.Standard]
|
|
|
|
userSections: ->
|
|
@_sections[Sections.User]
|
|
|
|
_registerListeners: ->
|
|
@listenTo SidebarActions.focusAccounts, @_onAccountsFocused
|
|
@listenTo FocusedPerspectiveStore, @_updateSections
|
|
@listenTo AccountStore, @_updateSections
|
|
@listenTo WorkspaceStore, @_updateSections
|
|
@listenTo ThreadCountsStore, @_updateSections
|
|
@listenTo DraftCountStore, @_updateSections
|
|
@listenTo CategoryStore, @_updateSections
|
|
@configSubscription = NylasEnv.config.observe(
|
|
'core.workspace.showUnreadForAllCategories',
|
|
@_updateSections
|
|
)
|
|
@configSubscription = NylasEnv.config.observe(
|
|
'core.accountSidebarCollapsed',
|
|
@_updateSections
|
|
)
|
|
return
|
|
|
|
_onAccountsFocused: (accounts) =>
|
|
Actions.focusDefaultMailboxPerspectiveForAccounts(accounts)
|
|
@_focusedAccounts = accounts
|
|
@_updateSections()
|
|
|
|
_updateSections: () =>
|
|
accounts = @_focusedAccounts
|
|
multiAccount = accounts.length > 1
|
|
|
|
@_sections[Sections.Standard] = SidebarSection.standardSectionForAccounts(accounts)
|
|
@_sections[Sections.User] = accounts.map (acc) ->
|
|
opts = {}
|
|
if multiAccount
|
|
opts.title = acc.label
|
|
opts.collapsible = true
|
|
SidebarSection.forUserCategories(acc, opts)
|
|
@trigger()
|
|
|
|
|
|
module.exports = new SidebarStore()
|