Skip to content

Commit

Permalink
store preference in localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
rzats committed Oct 1, 2024
1 parent 3f0a535 commit f50c93e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/components/dialogs/apiKeySelections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
5 changes: 3 additions & 2 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) => {
Expand Down

0 comments on commit f50c93e

Please sign in to comment.