Mailspring/internal_packages/account-sidebar/lib/sidebar-store.coffee
Juan Tejada d592474073 More account sidebar refactor + sections for unified inbox
- Refactors some of the old code which was 💩
  - Makes SidbarSection a factory for different types of items for the
    OutlineView
  - Decided not to create a OutlineViewItem.Model class since the only
    purpose it would serve would be to validate getters for props or for
    documentation, both of which are already done via React.PropTypes.
- Adds sections when looking at unified inbox and integrates with new
  mailbox perspecitve interface
- Updates OutlineViewItem a bit + styles
- Tests missing
2016-01-18 23:22:46 -08:00

68 lines
1.8 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'
SidebarActions = require './sidebar-actions'
Sections = {
"Standard",
"User"
}
class SidebarStore extends NylasStore
constructor: ->
@_sections = {}
# @_account = AccountStore.accounts()[0]
@_account = FocusedPerspectiveStore.current().account
@_registerListeners()
@_updateSections()
standardSection: ->
@_sections[Sections.Standard]
userSections: ->
@_sections[Sections.User]
_registerListeners: ->
@listenTo SidebarActions.selectAccount, @_onAccountSelected
@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
_onAccountSelected: (account) =>
if @_account isnt account
@_account = account
@_updateSections()
_updateSections: =>
accounts = if @_account? then [@_account] else AccountStore.accounts()
@_sections[Sections.Standard] = SidebarSection.standardSectionForAccounts(accounts)
@_sections[Sections.User] = accounts.map (acc) ->
SidebarSection.forUserCategories(acc)
@trigger()
module.exports = new SidebarStore()