React = require 'react' Immutable = require 'immutable' _ = require 'underscore' classNames = require 'classnames' {RetinaImg, Flexbox, DisclosureTriangle} = require 'nylas-component-kit' {Actions, AccountStore} = require 'nylas-exports' {PreferencesUIStore} = require 'nylas-exports' class PreferencesSidebarItem extends React.Component @displayName: 'PreferencesSidebarItem' @propTypes: accounts: React.PropTypes.array selection: React.PropTypes.instanceOf(Immutable.Map).isRequired tabItem: React.PropTypes.instanceOf(PreferencesUIStore.TabItem).isRequired constructor: -> @state = collapsed: true render: => {tabId, displayName, componentRequiresAccount} = @props.tabItem subitems = @_renderSubitems() subitemsComponent = if @state.collapsed subitemsComponent = false classes = classNames "item": true "active": tabId is @props.selection.get('tabId') "has-subitems": subitems isnt false
{displayName}
{subitemsComponent}
_renderSubitems: => if @props.tabItem.componentRequiresAccount @props.accounts.map (account) => classes = classNames "subitem": true "active": account.id is @props.selection.get('accountId')
  • @_onClickAccount(event, account.id)}> {account.emailAddress}
  • else return false _onClick: => if @props.tabItem.componentRequiresAccount @setState(collapsed: !@state.collapsed) else Actions.switchPreferencesTab(@props.tabItem.tabId) _onClickAccount: (event, accountId) => Actions.switchPreferencesTab(@props.tabItem.tabId, {accountId}) event.stopPropagation() class PreferencesSidebar extends React.Component @displayName: 'PreferencesSidebar' @propTypes: tabs: React.PropTypes.instanceOf(Immutable.List).isRequired selection: React.PropTypes.instanceOf(Immutable.Map).isRequired constructor: -> @state = accounts: AccountStore.accounts() componentDidMount: => @unsub = AccountStore.listen @_onAccountsChanged componentWillUnmount: => @unsub?() render: =>
    { @props.tabs.map (tabItem) => }
    _onAccountsChanged: => @setState(accounts: AccountStore.accounts()) module.exports = PreferencesSidebar