Skip to content

Commit

Permalink
Set default values based on URL params
Browse files Browse the repository at this point in the history
  • Loading branch information
rzats committed Mar 14, 2024
1 parent 3e88df5 commit a621fc5
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/modes/exportdata/ExportData.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,31 @@
}
}
const urlParams = new URLSearchParams(window.location.search);
// Overwrite default source & sensor if these are present in the URL
if (urlParams.has('source')) {
sourceValue = urlParams.get('source');
if (urlParams.has('sensor')) {
sensorValue = urlParams.get('sensor');
}
}
$: isWeekly = sensor ? sensor.isWeeklySignal : false;
$: formatDate = isWeekly ? (d) => formatWeek(d).replace('W', '') : formatDateISO;
let geoType = 'county';
let geoType = urlParams.has('geo') ? urlParams.get('geo') : 'county';
let startDate = new Date();
let endDate = new Date();
function initDate(date) {
const param = new DateParam(date);
endDate = param.sparkLineTimeFrame.max;
startDate = param.sparkLineTimeFrame.min;
// Populate date based on URL params or, if absent, the current date
startDate = urlParams.has('start') ? new Date(urlParams.get('start')) : param.sparkLineTimeFrame.min;
endDate = urlParams.has('end') ? new Date(urlParams.get('end')) : param.sparkLineTimeFrame.max;
}
$: initDate($currentDateObject);
Expand Down

0 comments on commit a621fc5

Please sign in to comment.