Skip to content

Commit

Permalink
Review fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
rzats committed Nov 27, 2024
1 parent b14e25b commit f673766
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src/components/dialogs/ImportAPIDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
</button>
<label
><input class="uk-checkbox" type="checkbox" bind:checked={$storeApiKeys} />
Save API key (auth token)</label
Save API key (auth token) between visits</label
>
</div>
</div>
Expand Down
3 changes: 1 addition & 2 deletions src/components/dialogs/dataSources/CDC.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
export let id: string;
let locations = regions[0].value;
let auth = $apiKey;
export function importDataSet() {
return importCDC({ locations, auth });
return importCDC({ locations, auth: $apiKey });
}
</script>

Expand Down
3 changes: 1 addition & 2 deletions src/components/dialogs/dataSources/FluView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
let regions = fluViewRegions[0].value;
let issue = DEFAULT_ISSUE;
let auth = $apiKey;
export function importDataSet() {
return importFluView({ regions, ...issue, auth });
return importFluView({ regions, ...issue, auth: $apiKey });
}
</script>

Expand Down
3 changes: 1 addition & 2 deletions src/components/dialogs/dataSources/GHT.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
export let id: string;
let locations = regions[0].value;
let auth = $apiKey;
let query = '';
export function importDataSet() {
return importGHT({ auth, locations, query });
return importGHT({ auth: $apiKey, locations, query });
}
</script>

Expand Down
3 changes: 1 addition & 2 deletions src/components/dialogs/dataSources/Quidel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
export let id: string;
let locations = regions[0].value;
let auth = $apiKey;
export function importDataSet() {
return importQuidel({ auth, locations });
return importQuidel({ auth: $apiKey, locations });
}
</script>

Expand Down
3 changes: 1 addition & 2 deletions src/components/dialogs/dataSources/Sensors.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
export let id: string;
let locations = regions[0].value;
let auth = $apiKey;
let names = sensorNames[0].value;
export function importDataSet() {
return importSensors({ auth, names, locations });
return importSensors({ auth: $apiKey, names, locations });
}
</script>

Expand Down
3 changes: 1 addition & 2 deletions src/components/dialogs/dataSources/Twitter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
export let id: string;
let locations = regions[0].value;
let auth = $apiKey;
let resolution: 'daily' | 'weekly' = 'daily';
export function importDataSet() {
return importTwitter({ auth, locations, resolution });
return importTwitter({ auth: $apiKey, locations, resolution });
}
</script>

Expand Down
52 changes: 11 additions & 41 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,25 @@ export const isShowingPoints = writable(defaults.showPoints);
export const initialViewport = writable(defaults.viewport);
export const navMode = writable(NavMode.autofit);

export function getStoreApiKeys() {
if (localStorage.getItem('store-api-key')) {
try {
// if we saved it, return it (as a boolean)
return localStorage.getItem('store-api-key') === 'true';
} catch {
// if parsing fails, saved value is bad, so clear it out
localStorage.removeItem('store-api-key');
}
}
// if parsing fails, return default of 'false'
return false;
}

export function getApiKey() {
if (localStorage.getItem('api-key')) {
try {
return localStorage.getItem('api-key')!;
} catch {
localStorage.removeItem('api-key');
}
}
return '';
}

export const storeApiKeys = writable(getStoreApiKeys());
export const storeApiKeys = writable(localStorage.getItem('store-api-key') === 'true');
storeApiKeys.subscribe((val) => {
if (!val) {
// reset local storage if user decides not to store API keys
localStorage.removeItem('api-key');
localStorage.setItem('store-api-key', val.toString());
if (val) {
// persist key from session to local storage
localStorage.setItem('api-key', sessionStorage.getItem('api-key') || '');
} else {
// persist API key if user decides to store API keys
const apiKey = sessionStorage.getItem('api-key')!;
if (apiKey) {
localStorage.setItem('api-key', apiKey);
}
// remove key from local storage
localStorage.removeItem('api-key');
}
// store the preference either way
localStorage.setItem('store-api-key', val.toString());
});

export const apiKey = writable(getApiKey());
export const apiKey = writable(localStorage.getItem('api-key')! || '');
apiKey.subscribe((val) => {
// always keep key around in session storage (resets on page refresh)
sessionStorage.setItem('api-key', val);
if (localStorage.getItem('store-api-key') === 'true') {
// store it in local storage (persistent)
localStorage.setItem('api-key', val.toString());
} else {
// keep it around in session storage (resets on page refresh)
sessionStorage.setItem('api-key', val.toString());
localStorage.setItem('api-key', val);
}
});

Expand Down

0 comments on commit f673766

Please sign in to comment.