diff --git a/web/src/components/events/EventItem.tsx b/web/src/components/events/EventItem.tsx index acc3ba4..582da1e 100644 --- a/web/src/components/events/EventItem.tsx +++ b/web/src/components/events/EventItem.tsx @@ -6,10 +6,12 @@ import Image from "../general/Image"; import { SingularEvent, EventFragment, - getClosestOccurrence, + getFutureOccurrences, } from "@/lib/event"; import { formatDate, formatExtendedDateTime } from "@/lib/date"; +const DATES_TO_SHOW = 2; + export const EventItem = ({ event, mode, @@ -19,8 +21,9 @@ export const EventItem = ({ mode: "list" | "calendar" | "singular"; size?: "small" | "medium" | "large"; }) => { - const nextOccurrence = getClosestOccurrence(event); + const futureOccurrences = getFutureOccurrences(event); const numOccurrences = event?.occurrences?.length ?? 0; + const nextOccurrence = numOccurrences ? futureOccurrences[0] : null; const featuredImage: any = event.featuredImage; return ( @@ -43,16 +46,15 @@ export const EventItem = ({
- Flere datoer ({numOccurrences}) -
- > + {futureOccurrences.slice(0, DATES_TO_SHOW).map((occurrence) => ( + + {formatDate(occurrence.start, "d. MMMM")} + + ))} + {futureOccurrences.length > DATES_TO_SHOW && ( + {`+${ + futureOccurrences.length - DATES_TO_SHOW + }`} )}- {formatExtendedDateTime(nextOccurrence.start)} + {formatExtendedDateTime(event.occurrence.start)}
)} {mode === "calendar" && diff --git a/web/src/components/events/eventItem.module.scss b/web/src/components/events/eventItem.module.scss index 2544140..b0a6bb1 100644 --- a/web/src/components/events/eventItem.module.scss +++ b/web/src/components/events/eventItem.module.scss @@ -111,7 +111,7 @@ align-items: center; } -.moreDates { +.datePill, .moreDates { display: inline-block; background: var(--color-background-secondary); color: var(--color-chateauBlue); diff --git a/web/src/lib/event.ts b/web/src/lib/event.ts index 998b1af..a7266ea 100644 --- a/web/src/lib/event.ts +++ b/web/src/lib/event.ts @@ -197,18 +197,16 @@ export function organizeEventsByDate(events: SingularEvent[]): EventsByDate { return eventsByDate; } -export function getClosestOccurrence(event: EventFragment) { +export function getFutureOccurrences(event: EventFragment): EventOccurrence[] { const today = startOfToday(); const occurrences = event?.occurrences ?? []; - const futureOccurrences = occurrences.filter((occurrence) => isAfter(toLocalTime(occurrence.start), today) ); futureOccurrences.sort( (a, b) => parseISO(a.start).getTime() - parseISO(b.start).getTime() ); - - return futureOccurrences[0]; + return futureOccurrences as EventOccurrence[]; } export function getEventPig(event: EventFragment): string | null {