Mailspring/internal_packages/preferences/lib/tabs/preferences-accounts.cjsx
Ben Gotow 0fb109aeee feat(reorder): Re-order mail rules (#1074) and accounts (#631)
Summary:
This implements EditableList re-ordering via a new prop callback.
You can drag and drop items in the mail rules list and the accounts list.
Note that you can't drag between lists - right now this is just to enable
re-ordering.

Test Plan: No new specs yet

Reviewers: evan, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D2495
2016-02-01 14:06:54 -08:00

65 lines
1.8 KiB
CoffeeScript

React = require 'react'
_ = require 'underscore'
{AccountStore, Actions} = require 'nylas-exports'
PreferencesAccountList = require './preferences-account-list'
PreferencesAccountDetails = require './preferences-account-details'
class PreferencesAccounts extends React.Component
@displayName: 'PreferencesAccounts'
constructor: (@props) ->
@state = @getStateFromStores()
@state.selected = @state.accounts[0]
componentDidMount: =>
@unsubscribe = AccountStore.listen @_onAccountsChanged
componentWillUnmount: =>
@unsubscribe?()
getStateFromStores: =>
accounts: AccountStore.accounts()
_onAccountsChanged: =>
@setState(@getStateFromStores())
# Update account list actions
#
_onAddAccount: =>
ipc = require('electron').ipcRenderer
ipc.send('command', 'application:add-account')
_onReorderAccount: (account, oldIdx, newIdx) =>
Actions.reorderAccount(account.id, newIdx)
_onSelectAccount: (account) =>
@setState(selected: account)
_onRemoveAccount: (account) =>
Actions.removeAccount(account.id)
# Update account actions
#
_onAccountUpdated: (account, updates) =>
Actions.updateAccount(account.id, updates)
render: =>
<section className="preferences-accounts">
<h2>Accounts</h2>
<div className="accounts-content">
<PreferencesAccountList
accounts={@state.accounts}
selected={@state.selected}
onAddAccount={@_onAddAccount}
onReorderAccount={@_onReorderAccount}
onSelectAccount={@_onSelectAccount}
onRemoveAccount={@_onRemoveAccount} />
<PreferencesAccountDetails
account={@state.selected}
onAccountUpdated={@_onAccountUpdated} />
</div>
</section>
module.exports = PreferencesAccounts