React = require 'react'
_ = require 'underscore'
{Actions, MailViewFilter, WorkspaceStore} = require("nylas-exports")
{ScrollRegion, Flexbox} = require("nylas-component-kit")
SidebarDividerItem = require("./account-sidebar-divider-item")
SidebarSheetItem = require("./account-sidebar-sheet-item")
AccountSidebarStore = require ("./account-sidebar-store")
AccountSidebarMailViewItem = require("./account-sidebar-mail-view-item")
{RetinaImg} = require 'nylas-component-kit'
class DisclosureTriangle extends React.Component
@displayName: 'DisclosureTriangle'
@propTypes:
collapsed: React.PropTypes.bool
visible: React.PropTypes.bool
onToggleCollapsed: React.PropTypes.func.isRequired
render: ->
classnames = "disclosure-triangle"
classnames += " visible" if @props.visible
classnames += " collapsed" if @props.collapsed
class AccountSidebar extends React.Component
@displayName: 'AccountSidebar'
@containerRequired: false
@containerStyles:
minWidth: 165
maxWidth: 210
constructor: (@props) ->
@state = @_getStateFromStores()
@state.collapsed = NylasEnv.config.get('core.accountSidebarCollapsed') ? {}
componentDidMount: =>
@unsubscribers = []
@unsubscribers.push AccountSidebarStore.listen @_onStoreChange
componentWillUnmount: =>
unsubscribe() for unsubscribe in @unsubscribers
render: =>
_sections: =>
@state.sections.map (section) =>
{section.label}
{@_itemComponents(section.items)}
_itemComponents: (items) =>
components = []
items.forEach (item) =>
components.push(
0}
onToggleCollapsed={ => @_onToggleCollapsed(item.id)}/>
{@_itemComponent(item)}
)
if item.children.length and not @state.collapsed[item.id]
components.push(
{@_itemComponents(item.children)}
)
components
_itemComponent: (item) =>
unless item instanceof WorkspaceStore.SidebarItem
throw new Error("AccountSidebar:_itemComponents: sections contained an \
item which was not a SidebarItem")
if item.component
Component = item.component
else if item.mailViewFilter
else if item.sheet
else
throw new Error("AccountSidebar:_itemComponents: each item must have a \
custom component, or a sheet or mailViewFilter")
_onStoreChange: =>
@setState @_getStateFromStores()
_onToggleCollapsed: (itemId) =>
collapsed = _.clone(@state.collapsed)
collapsed[itemId] = !collapsed[itemId]
NylasEnv.config.set('core.accountSidebarCollapsed', collapsed)
@setState({collapsed})
_getStateFromStores: =>
sections: AccountSidebarStore.sections()
selected: AccountSidebarStore.selected()
module.exports = AccountSidebar