Mailspring/internal_packages/preferences/lib/preferences-sidebar.cjsx
Juan Tejada 9f998d1964 refactor(rip-current-account): Rips out AccountStore.current
Summary:
- WIP: Need to fix tests and some errors!
- Refactors Category class to hold information about its type
- Refactors CategoryStore to rely on observables instead of local caches
- Adds and updates Observables and helpers
- Refactors ContactStore to hold entire cache of contacts instead of per
  current account
  - Same for ContactRankingStore and other stores
- Refactors method names for AccountStore + some helpers
- Updates MailViewFilter to hold an account
  - Adds basic Unified filter
- Replaces AccountStore.current calls with either:
  - The account of the currently focused MailViewFilter
  - The account associated with a thread, message, file, etc...
  - A parameter to be passed in
  - Arbitrarily, the first account in the AccountsStore

Test Plan: - Unit tests

Reviewers: evan, bengotow

Differential Revision: https://phab.nylas.com/D2423
2016-01-08 14:22:13 -08:00

99 lines
2.8 KiB
CoffeeScript

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 = <ul className="subitems">{subitems}</ul>
if @state.collapsed
subitemsComponent = false
classes = classNames
"item": true
"active": tabId is @props.selection.get('tabId')
"has-subitems": subitems isnt false
<div className={classes} onClick={@_onClick}>
<DisclosureTriangle
collapsed={@state.collapsed}
visible={subitems isnt false}
onToggleCollapsed={@_onClick} />
<div className="name">{displayName}</div>
{subitemsComponent}
</div>
_renderSubitems: =>
if @props.tabItem.componentRequiresAccount
@props.accounts.map (account) =>
classes = classNames
"subitem": true
"active": account.id is @props.selection.get('accountId')
<li key={account.id}
className={classes}
onClick={ (event) => @_onClickAccount(event, account.id)}>
{account.emailAddress}
</li>
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: =>
<div className="preferences-sidebar">
{ @props.tabs.map (tabItem) =>
<PreferencesSidebarItem
key={tabItem.tabId}
tabItem={tabItem}
accounts={@state.accounts}
selection={@props.selection} />
}
</div>
_onAccountsChanged: =>
@setState(accounts: AccountStore.accounts())
module.exports = PreferencesSidebar