Skip to content

Commit f673766

Browse files
committed
Review fixes #2
1 parent b14e25b commit f673766

File tree

8 files changed

+18
-54
lines changed

8 files changed

+18
-54
lines changed

src/components/dialogs/ImportAPIDialog.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
</button>
184184
<label
185185
><input class="uk-checkbox" type="checkbox" bind:checked={$storeApiKeys} />
186-
Save API key (auth token)</label
186+
Save API key (auth token) between visits</label
187187
>
188188
</div>
189189
</div>

src/components/dialogs/dataSources/CDC.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
export let id: string;
99
1010
let locations = regions[0].value;
11-
let auth = $apiKey;
1211
1312
export function importDataSet() {
14-
return importCDC({ locations, auth });
13+
return importCDC({ locations, auth: $apiKey });
1514
}
1615
</script>
1716

src/components/dialogs/dataSources/FluView.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
1212
let regions = fluViewRegions[0].value;
1313
let issue = DEFAULT_ISSUE;
14-
let auth = $apiKey;
1514
1615
export function importDataSet() {
17-
return importFluView({ regions, ...issue, auth });
16+
return importFluView({ regions, ...issue, auth: $apiKey });
1817
}
1918
</script>
2019

src/components/dialogs/dataSources/GHT.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
export let id: string;
99
1010
let locations = regions[0].value;
11-
let auth = $apiKey;
1211
let query = '';
1312
1413
export function importDataSet() {
15-
return importGHT({ auth, locations, query });
14+
return importGHT({ auth: $apiKey, locations, query });
1615
}
1716
</script>
1817

src/components/dialogs/dataSources/Quidel.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
export let id: string;
99
1010
let locations = regions[0].value;
11-
let auth = $apiKey;
1211
1312
export function importDataSet() {
14-
return importQuidel({ auth, locations });
13+
return importQuidel({ auth: $apiKey, locations });
1514
}
1615
</script>
1716

src/components/dialogs/dataSources/Sensors.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
export let id: string;
99
1010
let locations = regions[0].value;
11-
let auth = $apiKey;
1211
let names = sensorNames[0].value;
1312
1413
export function importDataSet() {
15-
return importSensors({ auth, names, locations });
14+
return importSensors({ auth: $apiKey, names, locations });
1615
}
1716
</script>
1817

src/components/dialogs/dataSources/Twitter.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
export let id: string;
99
1010
let locations = regions[0].value;
11-
let auth = $apiKey;
1211
let resolution: 'daily' | 'weekly' = 'daily';
1312
1413
export function importDataSet() {
15-
return importTwitter({ auth, locations, resolution });
14+
return importTwitter({ auth: $apiKey, locations, resolution });
1615
}
1716
</script>
1817

src/store.ts

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,55 +17,25 @@ export const isShowingPoints = writable(defaults.showPoints);
1717
export const initialViewport = writable(defaults.viewport);
1818
export const navMode = writable(NavMode.autofit);
1919

20-
export function getStoreApiKeys() {
21-
if (localStorage.getItem('store-api-key')) {
22-
try {
23-
// if we saved it, return it (as a boolean)
24-
return localStorage.getItem('store-api-key') === 'true';
25-
} catch {
26-
// if parsing fails, saved value is bad, so clear it out
27-
localStorage.removeItem('store-api-key');
28-
}
29-
}
30-
// if parsing fails, return default of 'false'
31-
return false;
32-
}
33-
34-
export function getApiKey() {
35-
if (localStorage.getItem('api-key')) {
36-
try {
37-
return localStorage.getItem('api-key')!;
38-
} catch {
39-
localStorage.removeItem('api-key');
40-
}
41-
}
42-
return '';
43-
}
44-
45-
export const storeApiKeys = writable(getStoreApiKeys());
20+
export const storeApiKeys = writable(localStorage.getItem('store-api-key') === 'true');
4621
storeApiKeys.subscribe((val) => {
47-
if (!val) {
48-
// reset local storage if user decides not to store API keys
49-
localStorage.removeItem('api-key');
22+
localStorage.setItem('store-api-key', val.toString());
23+
if (val) {
24+
// persist key from session to local storage
25+
localStorage.setItem('api-key', sessionStorage.getItem('api-key') || '');
5026
} else {
51-
// persist API key if user decides to store API keys
52-
const apiKey = sessionStorage.getItem('api-key')!;
53-
if (apiKey) {
54-
localStorage.setItem('api-key', apiKey);
55-
}
27+
// remove key from local storage
28+
localStorage.removeItem('api-key');
5629
}
57-
// store the preference either way
58-
localStorage.setItem('store-api-key', val.toString());
5930
});
6031

61-
export const apiKey = writable(getApiKey());
32+
export const apiKey = writable(localStorage.getItem('api-key')! || '');
6233
apiKey.subscribe((val) => {
34+
// always keep key around in session storage (resets on page refresh)
35+
sessionStorage.setItem('api-key', val);
6336
if (localStorage.getItem('store-api-key') === 'true') {
6437
// store it in local storage (persistent)
65-
localStorage.setItem('api-key', val.toString());
66-
} else {
67-
// keep it around in session storage (resets on page refresh)
68-
sessionStorage.setItem('api-key', val.toString());
38+
localStorage.setItem('api-key', val);
6939
}
7040
});
7141

0 commit comments

Comments
 (0)