React = require 'react' _ = require 'underscore' {AccountStore, DatabaseStore, EdgehillAPI} = require 'nylas-exports' {RetinaImg, Flexbox} = require 'nylas-component-kit' class PreferencesAccounts extends React.Component @displayName: 'PreferencesAccounts' constructor: (@props) -> @state = @getStateFromStores() componentDidMount: => @unsubscribe = AccountStore.listen @_onAccountChange componentWillUnmount: => @unsubscribe?() render: =>
{@_renderAccounts()}
{@_renderLinkedAccounts()}
_renderAccounts: => return false unless @state.accounts
Accounts:
{ @state.accounts.map (account) =>
{account.emailAddress}
{account.name || "No name provided."} ({account.displayProvider()})
}
_renderLinkedAccounts: => tokens = @getSecondaryTokens() return false unless tokens.length > 0
Linked Accounts:
{ tokens.map (token) =>
{@_renderLinkedAccount(token)}
}
_renderLinkedAccount: (token) =>
{token.provider}
getStateFromStores: => accounts: AccountStore.items() getSecondaryTokens: => return [] unless @props.config tokens = @props.config.get('tokens') || [] tokens = tokens.filter (token) -> token.provider isnt 'nylas' tokens _onAddAccount: => ipc = require('ipc') ipc.send('command', 'application:add-account') _onAccountChange: => @setState(@getStateFromStores()) _onUnlinkAccount: (account) => AccountStore.removeAccountId(account.id) _onUnlinkToken: (token) => module.exports = PreferencesAccounts