Skip to content

Commit

Permalink
use new function for filtering and sorting events
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Kim authored and Chris Kim committed Nov 30, 2023
1 parent 9c501d2 commit fd94eb9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/site/filters/liquid.js
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,32 @@ module.exports = function registerFilters() {
});
};

//* Filters and Sorts event dates (fieldDatetimeRangeTimezone) starting with the most upcoming event.
//* Also sorts press releases (fieldReleaseDate) from newest to oldest.
liquid.filters.filterAndSortEvents = data => {
if (!data) return null;
const currentTimestamp = moment().unix();

const filteredEvents = data.filter(event => {
const occurrenceArray = event.fieldDatetimeRangeTimezone.map(
occurrence => {
return occurrence.value;
},
);
const futureOccurrences = occurrenceArray.filter(
occurrence => occurrence >= currentTimestamp,
);

return futureOccurrences.length > 0;
});

return liquid.filters.sortByDateKey(
filteredEvents,
'fieldDatetimeRangeTimezone',
false,
);
};

//* paginatePages has limitations, it is not yet fully operational.
liquid.filters.paginatePages = (page, items, aria) => {
const perPage = 10;
Expand Down
5 changes: 4 additions & 1 deletion src/site/layouts/health_care_region_page.drupal.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@
</section>
{% elsif eventTeasersAll.entities.0.reverseFieldListingNode.entities.length %}
{% assign upcomingEvents = eventTeasersAll.entities.0.reverseFieldListingNode.entities %}
{% assign sortedEvents = upcomingEvents | sortByDateKey: 'fieldDatetimeRangeTimezone', false %}
{% comment %} {% assign filteredEvents = upcomingEvents | filterPastEvents %}
{% assign sortedEvents = filteredEvents | sortByDateKey: 'fieldDatetimeRangeTimezone', false %} {% endcomment %}

{% assign sortedEvents = upcomingEvents | filterAndSortEvents %}

<section>
<h2
Expand Down

0 comments on commit fd94eb9

Please sign in to comment.