fix(aliases): Properly set selected state on account update

This commit is contained in:
Juan Tejada 2016-05-18 17:34:36 -07:00
parent cf6428d94a
commit 18f0872794

View file

@ -1,7 +1,7 @@
import _ from 'underscore';
import React from 'react'; import React from 'react';
import {ipcRenderer} from 'electron'; import {ipcRenderer} from 'electron';
import {AccountStore, Actions} from 'nylas-exports'; import {AccountStore, Actions} from 'nylas-exports';
import PreferencesAccountList from './preferences-account-list'; import PreferencesAccountList from './preferences-account-list';
import PreferencesAccountDetails from './preferences-account-details'; import PreferencesAccountDetails from './preferences-account-details';
@ -13,7 +13,6 @@ class PreferencesAccounts extends React.Component {
constructor() { constructor() {
super(); super();
this.state = this.getStateFromStores(); this.state = this.getStateFromStores();
this.state.selected = this.state.accounts[0];
} }
componentDidMount() { componentDidMount() {
@ -24,12 +23,16 @@ class PreferencesAccounts extends React.Component {
this.unsubscribe(); this.unsubscribe();
} }
getStateFromStores() { getStateFromStores({selected} = {}) {
return {accounts: AccountStore.accounts()}; const accounts = AccountStore.accounts()
return {
accounts,
selected: selected ? _.findWhere(accounts, {id: selected.id}) : accounts[0],
};
} }
_onAccountsChanged = () => { _onAccountsChanged = () => {
this.setState(this.getStateFromStores()); this.setState(this.getStateFromStores(this.state));
} }
// Update account list actions // Update account list actions