diff --git a/src/components/dialogs/apiKeySelections.ts b/src/components/dialogs/apiKeySelections.ts index a3df7bc..39809b4 100644 --- a/src/components/dialogs/apiKeySelections.ts +++ b/src/components/dialogs/apiKeySelections.ts @@ -7,6 +7,18 @@ export default class ApiKeySelections { twitter = ''; } +export function getStoreApiKeys() { + try { + if (localStorage.getItem('store-api')) { + return JSON.parse(localStorage.getItem('store-api')!) as boolean; + } + return true; + } catch { + localStorage.removeItem('store-api'); + return true; + } +} + export function getApiKeySelections() { try { if (localStorage.getItem('api')) { diff --git a/src/store.ts b/src/store.ts index 512ffce..ac32df6 100644 --- a/src/store.ts +++ b/src/store.ts @@ -2,7 +2,7 @@ import { get, writable } from 'svelte/store'; import { NavMode } from './components/chartUtils'; import DataSet, { DataGroup } from './data/DataSet'; import deriveLinkDefaults, { getDirectLinkImpl } from './deriveLinkDefaults'; -import ApiKeySelections, { getApiKeySelections } from './components/dialogs/apiKeySelections'; +import { getApiKeySelections, getStoreApiKeys } from './components/dialogs/apiKeySelections'; declare const __VERSION__: string; @@ -18,12 +18,13 @@ export const isShowingPoints = writable(defaults.showPoints); export const initialViewport = writable(defaults.viewport); export const navMode = writable(NavMode.autofit); -export const storeApiKeys = writable(true); +export const storeApiKeys = writable(getStoreApiKeys()); storeApiKeys.subscribe((val) => { if (!val) { // reset local storage if user decides not to store API keys localStorage.removeItem('api'); } + localStorage.setItem('store-api', val.toString()); }); export const apiKeySelections = writable(getApiKeySelections()); apiKeySelections.subscribe((val) => {