2016-01-19 15:18:19 +08:00
|
|
|
NylasStore = require 'nylas-store'
|
|
|
|
_ = require 'underscore'
|
2016-01-22 06:12:56 +08:00
|
|
|
{Actions,
|
2016-01-19 15:18:19 +08:00
|
|
|
AccountStore,
|
|
|
|
ThreadCountsStore,
|
|
|
|
DraftCountStore,
|
|
|
|
WorkspaceStore,
|
|
|
|
FocusedPerspectiveStore,
|
|
|
|
CategoryStore} = require 'nylas-exports'
|
|
|
|
|
|
|
|
SidebarSection = require './sidebar-section'
|
2016-01-22 06:12:56 +08:00
|
|
|
SidebarActions = require './sidebar-actions'
|
2016-01-19 15:18:19 +08:00
|
|
|
|
|
|
|
Sections = {
|
|
|
|
"Standard",
|
|
|
|
"User"
|
|
|
|
}
|
|
|
|
|
|
|
|
class SidebarStore extends NylasStore
|
|
|
|
|
|
|
|
constructor: ->
|
|
|
|
@_sections = {}
|
2016-01-20 15:42:50 +08:00
|
|
|
@_sections[Sections.Standard] = {}
|
|
|
|
@_sections[Sections.User] = []
|
2016-01-22 06:12:56 +08:00
|
|
|
@_focusedAccounts = @accounts()
|
2016-01-19 15:18:19 +08:00
|
|
|
@_registerListeners()
|
|
|
|
@_updateSections()
|
|
|
|
|
2016-01-20 15:42:50 +08:00
|
|
|
accounts: ->
|
|
|
|
AccountStore.accounts()
|
|
|
|
|
|
|
|
focusedAccounts: ->
|
2016-01-22 06:12:56 +08:00
|
|
|
@_focusedAccounts
|
2016-01-20 15:42:50 +08:00
|
|
|
|
2016-01-19 15:18:19 +08:00
|
|
|
standardSection: ->
|
|
|
|
@_sections[Sections.Standard]
|
|
|
|
|
|
|
|
userSections: ->
|
|
|
|
@_sections[Sections.User]
|
|
|
|
|
|
|
|
_registerListeners: ->
|
2016-01-22 06:12:56 +08:00
|
|
|
@listenTo SidebarActions.focusAccounts, @_onAccountsFocused
|
|
|
|
@listenTo FocusedPerspectiveStore, @_updateSections
|
2016-01-19 15:18:19 +08:00
|
|
|
@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
|
|
|
|
|
2016-01-22 06:12:56 +08:00
|
|
|
_onAccountsFocused: (accounts) =>
|
|
|
|
Actions.focusDefaultMailboxPerspectiveForAccounts(accounts)
|
|
|
|
@_focusedAccounts = accounts
|
|
|
|
@_updateSections()
|
|
|
|
|
|
|
|
_updateSections: () =>
|
|
|
|
accounts = @_focusedAccounts
|
2016-01-21 09:09:05 +08:00
|
|
|
multiAccount = accounts.length > 1
|
2016-01-20 15:42:50 +08:00
|
|
|
|
2016-01-19 15:18:19 +08:00
|
|
|
@_sections[Sections.Standard] = SidebarSection.standardSectionForAccounts(accounts)
|
|
|
|
@_sections[Sections.User] = accounts.map (acc) ->
|
2016-01-21 09:09:05 +08:00
|
|
|
opts = {}
|
|
|
|
if multiAccount
|
|
|
|
opts.title = acc.label
|
|
|
|
opts.collapsible = true
|
|
|
|
SidebarSection.forUserCategories(acc, opts)
|
2016-01-19 15:18:19 +08:00
|
|
|
@trigger()
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = new SidebarStore()
|