Skip to content

Commit a621fc5

Browse files
committed
Set default values based on URL params
1 parent 3e88df5 commit a621fc5

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/modes/exportdata/ExportData.svelte

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,31 @@
2727
}
2828
}
2929
30+
const urlParams = new URLSearchParams(window.location.search);
31+
32+
// Overwrite default source & sensor if these are present in the URL
33+
if (urlParams.has('source')) {
34+
sourceValue = urlParams.get('source');
35+
36+
if (urlParams.has('sensor')) {
37+
sensorValue = urlParams.get('sensor');
38+
}
39+
}
40+
3041
$: isWeekly = sensor ? sensor.isWeeklySignal : false;
3142
$: formatDate = isWeekly ? (d) => formatWeek(d).replace('W', '') : formatDateISO;
3243
33-
let geoType = 'county';
44+
let geoType = urlParams.has('geo') ? urlParams.get('geo') : 'county';
3445
3546
let startDate = new Date();
3647
let endDate = new Date();
3748
3849
function initDate(date) {
3950
const param = new DateParam(date);
40-
endDate = param.sparkLineTimeFrame.max;
41-
startDate = param.sparkLineTimeFrame.min;
51+
52+
// Populate date based on URL params or, if absent, the current date
53+
startDate = urlParams.has('start') ? new Date(urlParams.get('start')) : param.sparkLineTimeFrame.min;
54+
endDate = urlParams.has('end') ? new Date(urlParams.get('end')) : param.sparkLineTimeFrame.max;
4255
}
4356
$: initDate($currentDateObject);
4457

0 commit comments

Comments
 (0)