Mailspring/internal_packages/account-sidebar/lib/sidebar-store.coffee
Juan Tejada b538ec050c Add account switcher back to sidebar:
- Account switcher can now switch between all accounts and each account
- Updates FocusedPerspectiveStore and Actions.focusDefaultMailboxPerspectiveForAccounts
  to focus a perspective for accountIds instead of for a single account,
  and updates methods
  - Adds helpers to CategoryStore and MailboxPerspective
  - Updates key commands to allow switch to unified inbox
2016-01-19 23:42:50 -08:00

70 lines
1.7 KiB
CoffeeScript

NylasStore = require 'nylas-store'
_ = require 'underscore'
{DatabaseStore,
AccountStore,
ThreadCountsStore,
DraftCountStore,
WorkspaceStore,
MailboxPerspective,
FocusedPerspectiveStore,
DestroyCategoryTask,
CategoryHelpers,
CategoryStore} = require 'nylas-exports'
SidebarSection = require './sidebar-section'
Sections = {
"Standard",
"User"
}
class SidebarStore extends NylasStore
constructor: ->
@_sections = {}
@_sections[Sections.Standard] = {}
@_sections[Sections.User] = []
@_registerListeners()
@_updateSections()
accounts: ->
AccountStore.accounts()
focusedAccounts: ->
accountIds = FocusedPerspectiveStore.current().accountIds
accountIds.map((accId) -> AccountStore.accountForId(accId))
standardSection: ->
@_sections[Sections.Standard]
userSections: ->
@_sections[Sections.User]
_registerListeners: ->
@listenTo AccountStore, @_updateSections
@listenTo WorkspaceStore, @_updateSections
@listenTo ThreadCountsStore, @_updateSections
@listenTo DraftCountStore, @_updateSections
@listenTo CategoryStore, @_updateSections
@listenTo FocusedPerspectiveStore, @_updateSections
@configSubscription = NylasEnv.config.observe(
'core.workspace.showUnreadForAllCategories',
@_updateSections
)
@configSubscription = NylasEnv.config.observe(
'core.accountSidebarCollapsed',
@_updateSections
)
return
_updateSections: =>
accounts = @focusedAccounts()
@_sections[Sections.Standard] = SidebarSection.standardSectionForAccounts(accounts)
@_sections[Sections.User] = accounts.map (acc) ->
SidebarSection.forUserCategories(acc)
@trigger()
module.exports = new SidebarStore()