React = require 'react' {Actions, MailViewFilter, WorkspaceStore} = require("nylas-exports") {ScrollRegion} = require("nylas-component-kit") SidebarDividerItem = require("./account-sidebar-divider-item") SidebarSheetItem = require("./account-sidebar-sheet-item") AccountSwitcher = require ("./account-switcher") AccountSidebarStore = require ("./account-sidebar-store") AccountSidebarMailViewItem = require("./account-sidebar-mail-view-item") {RetinaImg} = require 'nylas-component-kit' class AccountSidebar extends React.Component @displayName: 'AccountSidebar' @containerRequired: false @containerStyles: minWidth: 165 maxWidth: 210 constructor: (@props) -> @state = @_getStateFromStores() componentDidMount: => @unsubscribers = [] @unsubscribers.push AccountSidebarStore.listen @_onStoreChange componentWillUnmount: => unsubscribe() for unsubscribe in @unsubscribers render: =>
{@_sections()}
_sections: => @state.sections.map (section) =>
{section.label}
{@_itemComponents(section)}
_itemComponents: (section) => section.items.map (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() _getStateFromStores: => sections: AccountSidebarStore.sections() selected: AccountSidebarStore.selected() module.exports = AccountSidebar