2016-01-16 08:27:57 +08:00
|
|
|
_ = require 'underscore'
|
2016-01-19 03:39:53 +08:00
|
|
|
React = require 'react'
|
2016-01-21 05:04:06 +08:00
|
|
|
{OutlineView, ScrollRegion, Flexbox} = require 'nylas-component-kit'
|
2016-01-20 15:42:50 +08:00
|
|
|
AccountSwitcher = require './account-switcher'
|
2016-01-19 15:18:19 +08:00
|
|
|
SidebarStore = require '../sidebar-store'
|
2016-01-16 08:27:57 +08:00
|
|
|
|
2016-01-19 03:39:53 +08:00
|
|
|
|
2016-01-16 08:27:57 +08:00
|
|
|
class AccountSidebar extends React.Component
|
|
|
|
@displayName: 'AccountSidebar'
|
|
|
|
|
|
|
|
@containerRequired: false
|
|
|
|
@containerStyles:
|
|
|
|
minWidth: 165
|
|
|
|
maxWidth: 210
|
|
|
|
|
|
|
|
constructor: (@props) ->
|
|
|
|
@state = @_getStateFromStores()
|
|
|
|
|
|
|
|
componentDidMount: =>
|
|
|
|
@unsubscribers = []
|
2016-01-19 15:18:19 +08:00
|
|
|
@unsubscribers.push SidebarStore.listen @_onStoreChange
|
2016-01-16 08:27:57 +08:00
|
|
|
|
|
|
|
componentWillUnmount: =>
|
|
|
|
unsubscribe() for unsubscribe in @unsubscribers
|
|
|
|
|
|
|
|
_onStoreChange: =>
|
|
|
|
@setState @_getStateFromStores()
|
|
|
|
|
|
|
|
_getStateFromStores: =>
|
2016-01-20 15:42:50 +08:00
|
|
|
accounts: SidebarStore.accounts()
|
|
|
|
focusedAccounts: SidebarStore.focusedAccounts()
|
2016-01-19 15:18:19 +08:00
|
|
|
userSections: SidebarStore.userSections()
|
2016-01-20 15:42:50 +08:00
|
|
|
standardSection: SidebarStore.standardSection()
|
2016-01-16 08:27:57 +08:00
|
|
|
|
2016-01-19 15:18:19 +08:00
|
|
|
_renderUserSections: (sections) =>
|
|
|
|
sections.map (section) =>
|
|
|
|
<OutlineView key={section.title} {...section} />
|
2016-01-16 08:27:57 +08:00
|
|
|
|
|
|
|
render: =>
|
2016-01-20 15:42:50 +08:00
|
|
|
{accounts, focusedAccounts, userSections, standardSection} = @state
|
|
|
|
|
2016-01-21 05:04:06 +08:00
|
|
|
<Flexbox direction="column" style={order: 0, flexShrink: 1, flex: 1}>
|
2016-01-20 15:42:50 +08:00
|
|
|
<AccountSwitcher accounts={accounts} focusedAccounts={focusedAccounts} />
|
2016-01-21 05:04:06 +08:00
|
|
|
<ScrollRegion className="account-sidebar" style={order: 2}>
|
2016-01-20 15:42:50 +08:00
|
|
|
<div className="account-sidebar-sections">
|
|
|
|
<OutlineView {...standardSection} />
|
|
|
|
{@_renderUserSections(userSections)}
|
|
|
|
</div>
|
|
|
|
</ScrollRegion>
|
2016-01-21 05:04:06 +08:00
|
|
|
</Flexbox>
|
2016-01-16 08:27:57 +08:00
|
|
|
|
|
|
|
|
|
|
|
module.exports = AccountSidebar
|