From 3c50442d04238eedd0e867a19674d4e01c5a1bb7 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Mon, 22 Aug 2016 20:07:37 -0400 Subject: PLT-3841/PLT-3883 Fixed detection of local storage, persist system console team list after logout (#3849) * PLT-3841 Fixed check to see if local/session storage is available * PLT-3883 Saved selected teams in the admin console across a logout * Clarified the code that checks if local storage is available --- webapp/stores/admin_store.jsx | 4 ++-- webapp/stores/browser_store.jsx | 28 ++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) (limited to 'webapp') diff --git a/webapp/stores/admin_store.jsx b/webapp/stores/admin_store.jsx index 3be89c10b..4a68ec14c 100644 --- a/webapp/stores/admin_store.jsx +++ b/webapp/stores/admin_store.jsx @@ -140,7 +140,7 @@ class AdminStoreClass extends EventEmitter { } getSelectedTeams() { - const result = BrowserStore.getItem('seleted_teams'); + const result = BrowserStore.getItem('selected_teams'); if (!result) { return {}; } @@ -148,7 +148,7 @@ class AdminStoreClass extends EventEmitter { } saveSelectedTeams(teams) { - BrowserStore.setItem('seleted_teams', teams); + BrowserStore.setItem('selected_teams', teams); } } diff --git a/webapp/stores/browser_store.jsx b/webapp/stores/browser_store.jsx index 9acd8530c..4b8bae06b 100644 --- a/webapp/stores/browser_store.jsx +++ b/webapp/stores/browser_store.jsx @@ -20,6 +20,11 @@ function getPrefix() { } class BrowserStoreClass { + constructor() { + this.hasCheckedLocalStorage = false; + this.localStorageSupported = false; + } + setItem(name, value) { this.setGlobalItem(getPrefix() + name, value); } @@ -145,6 +150,7 @@ class BrowserStoreClass { const logoutId = sessionStorage.getItem('__logout__'); const serverVersion = this.getLastServerVersion(); const landingPageSeen = this.hasSeenLandingPage(); + const selectedTeams = this.getItem('selected_teams'); sessionStorage.clear(); localStorage.clear(); @@ -160,23 +166,27 @@ class BrowserStoreClass { if (landingPageSeen) { this.setLandingPageSeen(landingPageSeen); } + + if (selectedTeams) { + this.setItem('selected_teams', selectedTeams); + } } isLocalStorageSupported() { - if (this.checkedLocalStorageSupported !== '') { - return this.checkedLocalStorageSupported; + if (this.hasCheckedLocalStorage) { + return this.localStorageSupported; } + this.localStorageSupported = false; + try { localStorage.setItem('__testLocal__', '1'); - if (localStorage.getItem('__testLocal__') !== '1') { - this.checkedLocalStorageSupported = false; + if (localStorage.getItem('__testLocal__') === '1') { + this.localStorageSupported = true; } localStorage.removeItem('__testLocal__', '1'); - - this.checkedLocalStorageSupported = true; } catch (e) { - this.checkedLocalStorageSupported = false; + this.localStorageSupported = false; } try { @@ -187,7 +197,9 @@ class BrowserStoreClass { browserHistory.push(window.location.origin + '/error?title=' + notSupportedParams.title + '&message=' + notSupportedParams.message); } - return this.checkedLocalStorageSupported; + this.hasCheckedLocalStorage = true; + + return this.localStorageSupported; } hasSeenLandingPage() { -- cgit v1.2.3-1-g7c22