From 410fc43bdf0302732bbdce50a3bfcb7b28b21df9 Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Sat, 13 Jul 2024 21:47:06 +0200 Subject: [PATCH] don't show more than two months in event calendar by default --- web/src/components/events/EventContainer.tsx | 53 ++++++++++++-------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/web/src/components/events/EventContainer.tsx b/web/src/components/events/EventContainer.tsx index 9f1a663..3b274ea 100644 --- a/web/src/components/events/EventContainer.tsx +++ b/web/src/components/events/EventContainer.tsx @@ -44,10 +44,10 @@ export const EventContainer = ({ const [venue, setVenue] = useQueryState("venue", parseAsString); const resetFilters = () => { - setCategory(null) - setOrganizer(null) - setVenue(null) - } + setCategory(null); + setOrganizer(null); + setVenue(null); + }; /* Allow filtering on all categories that are configured to be shown */ const filterableCategories = eventCategories.filter((x) => x.showInFilters); @@ -193,30 +193,43 @@ const CalendarDay = ({ ); const EventCalendar = ({ events }: { events: EventFragment[] }) => { + const [showAll, setShowAll] = useState(false); + const futureSingularEvents = getSingularEvents(events).filter( (x) => x.occurrence?.start && isTodayOrFuture(x.occurrence.start) ); - const eventsByDate = organizeEventsInCalendar(futureSingularEvents); + const yearMonths = Object.keys(eventsByDate); + const visibleYearMonths = showAll ? yearMonths : yearMonths.slice(0, 2); return ( -
- {Object.keys(eventsByDate).map((yearMonth) => ( -
-

{formatYearMonth(yearMonth)}

- {Object.keys(eventsByDate[yearMonth]).map((week) => ( -
- {Object.keys(eventsByDate[yearMonth][week]).map((day) => ( - + <> +
+ {Object.keys(eventsByDate) + .filter((yearMonth) => visibleYearMonths.includes(yearMonth)) + .map((yearMonth) => ( +
+

{formatYearMonth(yearMonth)}

+ {Object.keys(eventsByDate[yearMonth]).map((week) => ( +
+ {Object.keys(eventsByDate[yearMonth][week]).map((day) => ( + + ))} +
))}
))} -
- ))} -
+
+ {!showAll && yearMonths.length > 2 && ( + + )} + ); };