From 47a992ccf4bea7ab2dd57967738233b069031ffa Mon Sep 17 00:00:00 2001 From: tree Date: Sat, 2 Mar 2024 17:50:50 +0100 Subject: [PATCH] update events --- src/components/EventsPage.astro | 58 +++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/src/components/EventsPage.astro b/src/components/EventsPage.astro index 9bcdd62..6f967df 100644 --- a/src/components/EventsPage.astro +++ b/src/components/EventsPage.astro @@ -9,7 +9,17 @@ import { types, countryNames } from '../lib/events.js'; const { type: selectedType } = Astro.props; const { country: selectedCountry } = Astro.props; -let typeObj = selectedType ? types.find(t => t.id === selectedType) : null +const typeObj = selectedType ? types.find(t => t.id === selectedType) : null +const countryObj = selectedCountry ? { name: countryNames[selectedCountry] } : null + +let title = 'Events'; +if (selectedType) { + title = typeObj.plural +} +if (selectedCountry) { + title = 'Events in ' + countryObj.name +} + let events = core.events; if (selectedType) { @@ -32,13 +42,14 @@ function eventsFilter (year, future=true) { } } -const currentYear = "2024"; -const pastYears = [ 2023, 2024 ]; +const pastYears = [...new Set(events.map(e => e.date.match(/^(\d{4})/)[1]))]; const upcoming = events.filter(x => x.date.match(/^2024/)) const past = {} +let pastTotal = 0 for (const year of pastYears.reverse()) { past[year] = events.filter(eventsFilter(year, false)).reverse() + pastTotal += past[year].length } let places = [{ id: '', country: 'All countries', num: core.events.length }]; @@ -60,11 +71,11 @@ for (const ev of core.events) { places = places.sort((x, y) => x.num < y.num ? 1 : -1) --- - +
-
+
{types.map((type) => ( {type.plural} ({type.id ? core.events.filter(obj => obj.type === type.id).length : core.events.length}) @@ -86,24 +97,31 @@ places = places.sort((x, y) => x.num < y.num ? 1 : -1) -

Upcoming {selectedType ? ` ${typeObj.plural} ` : ''}({upcoming.length})

- -
- {upcoming.map((event) => ( - - ))} -
- -

Past {selectedType ? ` ${typeObj.plural} ` : ''}({events.length-upcoming.length})

- {pastYears.map((year) => ( - past[year].length > 0 && -

{year} ({past[year].length})

-
- {past[year]?.map((event) => ( + {upcoming.length > 0 && +
+

Upcoming {title} ({upcoming.length})

+
+ {upcoming.map((event) => ( ))}
- ))} +
+ } + + {pastTotal > 0 && +
+

Past {title} ({events.length-upcoming.length})

+ {pastYears.map((year) => ( + past[year].length > 0 && +

{year} ({past[year].length})

+
+ {past[year]?.map((event) => ( + + ))} +
+ ))} +
+ }

Source repository