From 18f0872794e057e8ba8f1846082c37aed9e4ef15 Mon Sep 17 00:00:00 2001 From: Juan Tejada Date: Wed, 18 May 2016 17:34:36 -0700 Subject: [PATCH] fix(aliases): Properly set selected state on account update --- .../preferences/lib/tabs/preferences-accounts.jsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/internal_packages/preferences/lib/tabs/preferences-accounts.jsx b/internal_packages/preferences/lib/tabs/preferences-accounts.jsx index 3725012d6..5f9ca16a8 100644 --- a/internal_packages/preferences/lib/tabs/preferences-accounts.jsx +++ b/internal_packages/preferences/lib/tabs/preferences-accounts.jsx @@ -1,7 +1,7 @@ +import _ from 'underscore'; import React from 'react'; import {ipcRenderer} from 'electron'; import {AccountStore, Actions} from 'nylas-exports'; - import PreferencesAccountList from './preferences-account-list'; import PreferencesAccountDetails from './preferences-account-details'; @@ -13,7 +13,6 @@ class PreferencesAccounts extends React.Component { constructor() { super(); this.state = this.getStateFromStores(); - this.state.selected = this.state.accounts[0]; } componentDidMount() { @@ -24,12 +23,16 @@ class PreferencesAccounts extends React.Component { this.unsubscribe(); } - getStateFromStores() { - return {accounts: AccountStore.accounts()}; + getStateFromStores({selected} = {}) { + const accounts = AccountStore.accounts() + return { + accounts, + selected: selected ? _.findWhere(accounts, {id: selected.id}) : accounts[0], + }; } _onAccountsChanged = () => { - this.setState(this.getStateFromStores()); + this.setState(this.getStateFromStores(this.state)); } // Update account list actions