From 54a74e317d4e968348db0f588e8dca68e63cb839 Mon Sep 17 00:00:00 2001 From: Juan Tejada Date: Thu, 16 Jun 2016 16:40:47 -0700 Subject: [PATCH] fix(sidebar): Make sure saved sidebar accts are correct - Sidebar accounts may become invalid when switching from staging to prod --- src/flux/stores/account-store.coffee | 3 +++ src/flux/stores/focused-perspective-store.coffee | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/flux/stores/account-store.coffee b/src/flux/stores/account-store.coffee index e0f8e6429..85b527f06 100644 --- a/src/flux/stores/account-store.coffee +++ b/src/flux/stores/account-store.coffee @@ -218,6 +218,9 @@ class AccountStore extends NylasStore accounts: => @_accounts + accountIds: => + _.pluck(@_accounts, 'id') + accountsForItems: (items) => accounts = {} items.forEach ({accountId}) => diff --git a/src/flux/stores/focused-perspective-store.coffee b/src/flux/stores/focused-perspective-store.coffee index 5be1e93e0..58d60b93d 100644 --- a/src/flux/stores/focused-perspective-store.coffee +++ b/src/flux/stores/focused-perspective-store.coffee @@ -116,7 +116,10 @@ class FocusedPerspectiveStore extends NylasStore @_current sidebarAccountIds: => - NylasEnv.savedState.sidebarAccountIds ?= AccountStore.accounts().map((acc) => acc.id) + NylasEnv.savedState.sidebarAccountIds ?= AccountStore.accountIds() + accIdsAreInvalid = not NylasEnv.savedState.sidebarAccountIds.every((accId) => AccountStore.accountForId(accId)?) + if accIdsAreInvalid + NylasEnv.savedState.sidebarAccountIds = AccountStore.accountIds() return NylasEnv.savedState.sidebarAccountIds module.exports = new FocusedPerspectiveStore()