|
4 | 4 | import type { LabelValue } from '../../../data/data'; |
5 | 5 | import SelectField from '../inputs/SelectField.svelte'; |
6 | 6 | import TextField from '../inputs/TextField.svelte'; |
7 | | - import { formSelections } from '../../../store'; |
| 7 | + import { apiKey, formSelections } from '../../../store'; |
8 | 8 |
|
9 | 9 | export let id: string; |
10 | | -
|
11 | | - let api_key = ''; |
12 | 10 | let data_source = $formSelections.covidcast.dataSource; |
13 | 11 | let signal = $formSelections.covidcast.signal; |
14 | 12 | let geo_type = $formSelections.covidcast.geoType; |
15 | 13 | let geo_value = $formSelections.covidcast.geoValue; |
16 | | - let form_key = ''; |
17 | 14 | let valid_key = true; |
18 | 15 |
|
19 | 16 | let dataSources: (LabelValue & { signals: string[] })[] = []; |
|
38 | 35 | }; |
39 | 36 |
|
40 | 37 | function fetchMetadata() { |
41 | | - fetchCOVIDcastMeta(form_key).then((res) => { |
| 38 | + fetchCOVIDcastMeta($apiKey).then((res) => { |
42 | 39 | if (res.length == 0) { |
43 | 40 | valid_key = false; |
44 | 41 | } else { |
45 | 42 | valid_key = true; |
46 | | - api_key = form_key; // API key is valid -> use it to fetch data later on |
47 | 43 | geoTypes = [...new Set(res.map((d) => d.geo_type))]; |
48 | 44 | const byDataSource = new Map<string, LabelValue & { signals: string[] }>(); |
49 | 45 | for (const row of res) { |
|
71 | 67 | }); |
72 | 68 |
|
73 | 69 | export function importDataSet() { |
74 | | - return fetchCOVIDcastMeta(api_key).then((res) => { |
| 70 | + return fetchCOVIDcastMeta($apiKey).then((res) => { |
75 | 71 | const meta = res.filter((row) => row.data_source === data_source && row.signal === signal); |
76 | 72 | const time_type = meta[0].time_type; |
77 | | - return importCOVIDcast({ data_source, signal, geo_type, geo_value, time_type, api_key }); |
| 73 | + return importCOVIDcast({ data_source, signal, geo_type, geo_value, time_type, api_key: $apiKey }); |
78 | 74 | }); |
79 | 75 | } |
80 | 76 | </script> |
|
91 | 87 | class:uk-form-danger={!valid_key} |
92 | 88 | name="api_key" |
93 | 89 | required={false} |
94 | | - bind:value={form_key} |
| 90 | + bind:value={$apiKey} |
95 | 91 | on:input={debounce(() => fetchMetadata(), 500)} |
96 | 92 | /> |
97 | 93 | {#if !valid_key} |
|
0 commit comments