Skip to content

Commit

Permalink
Store region in URL
Browse files Browse the repository at this point in the history
  • Loading branch information
juberti committed Apr 23, 2024
1 parent 660e770 commit c599802
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions website/src/components/DataGrid.astro
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,23 @@ import 'ag-grid-community/styles/ag-theme-quartz.css';
let selectedRegion = urlParams.get('r') ?? 'sea';
let selectedRegionData = [];

function updateRegion(region: string) {
function setUrlParam(key: string, value: string) {
const url = new URL(window.location.href);
url.searchParams.set(key, value);
window.history.replaceState({}, '', url);
}

function updateRegion(region: string, updateUrl: boolean = true) {
selectedRegion = region;
gridData.forEach((regionData) => {
if (regionData.region === region) {
selectedRegionData = regionData.results;
gridApi.setGridOption("rowData", selectedRegionData);
}
});
if (updateUrl) {
setUrlParam('r', region);
}
};

// Returns the background color for the cell based on the value
Expand Down Expand Up @@ -152,7 +161,7 @@ import 'ag-grid-community/styles/ag-theme-quartz.css';
// set the selected region and populate the grid
const selectedRegionRadio = document.querySelector(`input[name=selectedRegion][value=${selectedRegion}]`) as HTMLInputElement;
selectedRegionRadio.checked = true;
updateRegion(selectedRegion);
updateRegion(selectedRegion, false);

// Add text for our last updated date
const ourDiv = document.getElementById('lastUpdated');
Expand Down

0 comments on commit c599802

Please sign in to comment.