Skip to content

Commit f50c93e

Browse files
committed
store preference in localhost
1 parent 3f0a535 commit f50c93e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/components/dialogs/apiKeySelections.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ export default class ApiKeySelections {
77
twitter = '';
88
}
99

10+
export function getStoreApiKeys() {
11+
try {
12+
if (localStorage.getItem('store-api')) {
13+
return JSON.parse(localStorage.getItem('store-api')!) as boolean;
14+
}
15+
return true;
16+
} catch {
17+
localStorage.removeItem('store-api');
18+
return true;
19+
}
20+
}
21+
1022
export function getApiKeySelections() {
1123
try {
1224
if (localStorage.getItem('api')) {

src/store.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { get, writable } from 'svelte/store';
22
import { NavMode } from './components/chartUtils';
33
import DataSet, { DataGroup } from './data/DataSet';
44
import deriveLinkDefaults, { getDirectLinkImpl } from './deriveLinkDefaults';
5-
import ApiKeySelections, { getApiKeySelections } from './components/dialogs/apiKeySelections';
5+
import { getApiKeySelections, getStoreApiKeys } from './components/dialogs/apiKeySelections';
66

77
declare const __VERSION__: string;
88

@@ -18,12 +18,13 @@ export const isShowingPoints = writable(defaults.showPoints);
1818
export const initialViewport = writable(defaults.viewport);
1919
export const navMode = writable(NavMode.autofit);
2020

21-
export const storeApiKeys = writable(true);
21+
export const storeApiKeys = writable(getStoreApiKeys());
2222
storeApiKeys.subscribe((val) => {
2323
if (!val) {
2424
// reset local storage if user decides not to store API keys
2525
localStorage.removeItem('api');
2626
}
27+
localStorage.setItem('store-api', val.toString());
2728
});
2829
export const apiKeySelections = writable(getApiKeySelections());
2930
apiKeySelections.subscribe((val) => {

0 commit comments

Comments
 (0)