2015-11-24 04:20:51 +08:00
|
|
|
React = require 'react'
|
|
|
|
_ = require 'underscore'
|
2015-12-01 03:43:49 +08:00
|
|
|
{RetinaImg,
|
|
|
|
Flexbox,
|
|
|
|
ConfigPropContainer,
|
|
|
|
ScrollRegion} = require 'nylas-component-kit'
|
|
|
|
{PreferencesUIStore} = require 'nylas-exports'
|
2015-11-24 04:20:51 +08:00
|
|
|
|
|
|
|
PreferencesSidebar = require './preferences-sidebar'
|
|
|
|
|
|
|
|
class PreferencesRoot extends React.Component
|
|
|
|
@displayName: 'PreferencesRoot'
|
|
|
|
@containerRequired: false
|
|
|
|
|
|
|
|
constructor: (@props) ->
|
|
|
|
@state = @getStateFromStores()
|
|
|
|
|
|
|
|
componentDidMount: =>
|
|
|
|
@unlisteners = []
|
2015-12-01 03:43:49 +08:00
|
|
|
@unlisteners.push PreferencesUIStore.listen =>
|
2015-11-24 04:20:51 +08:00
|
|
|
@setState(@getStateFromStores())
|
|
|
|
|
|
|
|
componentWillUnmount: =>
|
|
|
|
unlisten() for unlisten in @unlisteners
|
|
|
|
|
|
|
|
getStateFromStores: =>
|
2015-12-01 03:43:49 +08:00
|
|
|
tabs: PreferencesUIStore.tabs()
|
|
|
|
selection: PreferencesUIStore.selection()
|
2015-11-24 04:20:51 +08:00
|
|
|
|
|
|
|
render: =>
|
2015-12-01 03:43:49 +08:00
|
|
|
tabId = @state.selection.get('tabId')
|
|
|
|
tab = @state.tabs.find (s) => s.tabId is tabId
|
2015-11-24 04:20:51 +08:00
|
|
|
|
2015-12-01 03:43:49 +08:00
|
|
|
if tab
|
|
|
|
bodyElement = <tab.component accountId={@state.selection.get('accountId')} />
|
2015-11-24 04:20:51 +08:00
|
|
|
else
|
2015-12-01 03:43:49 +08:00
|
|
|
bodyElement = <div></div>
|
2015-11-24 04:20:51 +08:00
|
|
|
|
|
|
|
<Flexbox direction="row" className="preferences-wrap">
|
2015-12-01 03:43:49 +08:00
|
|
|
<PreferencesSidebar tabs={@state.tabs}
|
|
|
|
selection={@state.selection} />
|
2015-11-24 04:20:51 +08:00
|
|
|
<ScrollRegion className="preferences-content">
|
|
|
|
<ConfigPropContainer>{bodyElement}</ConfigPropContainer>
|
|
|
|
</ScrollRegion>
|
|
|
|
</Flexbox>
|
|
|
|
|
|
|
|
module.exports = PreferencesRoot
|