Skip to content

Commit

Permalink
added function to pick up url data
Browse files Browse the repository at this point in the history
  • Loading branch information
davenichols-DHLS committed Aug 19, 2024
1 parent 0ffe360 commit 8ab23f5
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion blocks/events/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,31 @@ const TYPES = [
'Webinar',
];

function filterUrl() {
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');

Check failure on line 24 in blocks/events/events.js

View workflow job for this annotation

GitHub Actions / build

Assignment to function parameter 'name'

Check failure on line 24 in blocks/events/events.js

View workflow job for this annotation

GitHub Actions / build

Unnecessary escape character: \[
const regex = new RegExp('[\\?&]' + name + '=([^&#]*)');

Check failure on line 25 in blocks/events/events.js

View workflow job for this annotation

GitHub Actions / build

Unexpected string concatenation
const results = regex.exec(location.search);

Check failure on line 26 in blocks/events/events.js

View workflow job for this annotation

GitHub Actions / build

Unexpected use of 'location'
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
}

// Get URL parameters
const eventTypeParam = getUrlParameter('type');
const regionParam = getUrlParameter('region');

// Select the checkbox with the ID that matches the region
const regionCheckbox = document.getElementById(regionParam);
if (regionCheckbox) {
regionCheckbox.checked = true;
}

// Select the checkbox with the ID that matches the event type
const typeCheckbox = document.getElementById(eventTypeParam);
if (typeCheckbox) {
typeCheckbox.checked = true;
}
}

async function fetchPostData() {
try {
const response = await fetch('/query-index.json');
Expand Down Expand Up @@ -231,6 +256,7 @@ async function buildSidePanel(currentPage, eventData) {
const checkboxes = sidePanel.querySelectorAll('.select .dropdown-menu .filter-item');
checkboxes.forEach((checkbox) => {
checkbox.addEventListener('change', (event) => {
console.log(eventData);

Check warning on line 259 in blocks/events/events.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
handleCheckboxChange(event, eventData);
});
});
Expand All @@ -256,7 +282,8 @@ function displayPage(page, events) {

function handlePagination(page, events) {
currentPageNumber = page;
displayPage(currentPageNumber, events); // Update UI with new page
const filteredEvents = filterEvents(events, eventType, region);

Check failure on line 285 in blocks/events/events.js

View workflow job for this annotation

GitHub Actions / build

'filterEvents' is not defined

Check failure on line 285 in blocks/events/events.js

View workflow job for this annotation

GitHub Actions / build

'eventType' is not defined

Check failure on line 285 in blocks/events/events.js

View workflow job for this annotation

GitHub Actions / build

'region' is not defined
displayPage(currentPageNumber, filteredEvents); // Update UI with new page
}

function generatePaginationButtons(totalPages, currentPage, events) {
Expand Down Expand Up @@ -319,4 +346,7 @@ export default async function decorate(block) {

displayPage(currentPageNumber, eventsToshow);
}

filterUrl();
//handleCheckboxChange('event', eventData);

Check failure on line 351 in blocks/events/events.js

View workflow job for this annotation

GitHub Actions / build

Expected exception block, space or tab after '//' in comment
}

0 comments on commit 8ab23f5

Please sign in to comment.