fix(sidebar): Correctly show all accounts in sidebar during initial sync

Ref #1587
This commit is contained in:
Juan Tejada 2016-11-16 22:46:27 -08:00
parent 69aaf27709
commit 5c7518e958
2 changed files with 12 additions and 3 deletions

View file

@ -1,5 +1,5 @@
_ = require 'underscore' _ = require 'underscore'
{Actions, AccountStore, MenuHelpers} = require 'nylas-exports' {Actions, MenuHelpers} = require 'nylas-exports'
class AccountCommands class AccountCommands

View file

@ -12,6 +12,7 @@ class FocusedPerspectiveStore extends NylasStore {
constructor() { constructor() {
super() super()
this._current = MailboxPerspective.forNothing(); this._current = MailboxPerspective.forNothing();
this._initialized = false
this.listenTo(CategoryStore, this._onCategoryStoreChanged); this.listenTo(CategoryStore, this._onCategoryStoreChanged);
this.listenTo(Actions.focusMailboxPerspective, this._onFocusPerspective); this.listenTo(Actions.focusMailboxPerspective, this._onFocusPerspective);
@ -80,14 +81,17 @@ class FocusedPerspectiveStore extends NylasStore {
if (json) { if (json) {
perspective = MailboxPerspective.fromJSON(json); perspective = MailboxPerspective.fromJSON(json);
} }
this._initialized = true
if (!perspective || !this._isValidPerspective(perspective)) { if (!perspective || !this._isValidPerspective(perspective)) {
perspective = this._defaultPerspective(); perspective = this._defaultPerspective();
sidebarAccountIds = perspective.accountIds; sidebarAccountIds = perspective.accountIds;
this._initialized = false
} }
if (!sidebarAccountIds || !this._isValidAccountSet(sidebarAccountIds) || sidebarAccountIds.length < perspective.accountIds.length) { if (!sidebarAccountIds || !this._isValidAccountSet(sidebarAccountIds) || sidebarAccountIds.length < perspective.accountIds.length) {
sidebarAccountIds = perspective.accountIds; sidebarAccountIds = perspective.accountIds;
this._initialized = false
} }
this._setPerspective(perspective, sidebarAccountIds); this._setPerspective(perspective, sidebarAccountIds);
@ -95,7 +99,7 @@ class FocusedPerspectiveStore extends NylasStore {
// Inbound Events // Inbound Events
_onCategoryStoreChanged = () => { _onCategoryStoreChanged = () => {
if (this._current.isEqual(MailboxPerspective.forNothing())) { if (!this._initialized) {
this._initializeFromSavedState(); this._initializeFromSavedState();
} else if (!this._isValidPerspective(this._current)) { } else if (!this._isValidPerspective(this._current)) {
this._setPerspective(this._defaultPerspective(this._current.accountIds)); this._setPerspective(this._defaultPerspective(this._current.accountIds));
@ -153,7 +157,12 @@ class FocusedPerspectiveStore extends NylasStore {
shouldTrigger = true; shouldTrigger = true;
} }
if (sidebarAccountIds && !_.isEqual(NylasEnv.savedState.sidebarAccountIds, sidebarAccountIds)) { const shouldSaveSidebarAccountIds = (
sidebarAccountIds &&
!_.isEqual(NylasEnv.savedState.sidebarAccountIds, sidebarAccountIds) &&
this._initialized === true
)
if (shouldSaveSidebarAccountIds) {
NylasEnv.savedState.sidebarAccountIds = sidebarAccountIds; NylasEnv.savedState.sidebarAccountIds = sidebarAccountIds;
shouldTrigger = true; shouldTrigger = true;
} }