use singular events in upcoming events
This commit is contained in:
@ -16,7 +16,7 @@ export const EventItem = ({
|
|||||||
size,
|
size,
|
||||||
}: {
|
}: {
|
||||||
event: SingularEvent | EventFragment;
|
event: SingularEvent | EventFragment;
|
||||||
mode: "list" | "calendar";
|
mode: "list" | "calendar" | "singular";
|
||||||
size?: "small" | "medium" | "large";
|
size?: "small" | "medium" | "large";
|
||||||
}) => {
|
}) => {
|
||||||
const nextOccurrence = getClosestOccurrence(event);
|
const nextOccurrence = getClosestOccurrence(event);
|
||||||
@ -55,6 +55,13 @@ export const EventItem = ({
|
|||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
{mode === "singular" &&
|
||||||
|
"occurrence" in event &&
|
||||||
|
event.occurrence?.start && (
|
||||||
|
<p className={styles.details}>
|
||||||
|
{formatDate(event.occurrence?.start, commonDateTimeFormat)}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
{mode === "calendar" &&
|
{mode === "calendar" &&
|
||||||
"occurrence" in event &&
|
"occurrence" in event &&
|
||||||
event.occurrence?.start && (
|
event.occurrence?.start && (
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
import { EventFragment } from "@/gql/graphql";
|
import { EventFragment } from "@/gql/graphql";
|
||||||
import { EventItem } from "./EventItem";
|
import { EventItem } from "./EventItem";
|
||||||
|
import { sortSingularEvents, getSingularEvents } from "@/lib/event";
|
||||||
import styles from "./upcomingEvents.module.scss";
|
import styles from "./upcomingEvents.module.scss";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
||||||
export const UpcomingEvents = ({ events }: { events: EventFragment[] }) => {
|
export const UpcomingEvents = ({ events }: { events: EventFragment[] }) => {
|
||||||
|
const upcomingSingularEvents = sortSingularEvents(getSingularEvents(events));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className={styles.upcomingWrapper}>
|
<section className={styles.upcomingWrapper}>
|
||||||
<h2 className="circlehead">
|
<h2 className="circlehead">
|
||||||
@ -13,8 +16,13 @@ export const UpcomingEvents = ({ events }: { events: EventFragment[] }) => {
|
|||||||
Denne uka på Chateau Neuf
|
Denne uka på Chateau Neuf
|
||||||
</h2>
|
</h2>
|
||||||
<ul className={styles.eventList}>
|
<ul className={styles.eventList}>
|
||||||
{events.slice(0, 5).map((event) => (
|
{upcomingSingularEvents.slice(0, 10).map((event) => (
|
||||||
<EventItem key={event.id} event={event} mode="list" size="medium" />
|
<EventItem
|
||||||
|
key={event.id}
|
||||||
|
event={event}
|
||||||
|
mode="singular"
|
||||||
|
size="medium"
|
||||||
|
/>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
<div className={styles.calendarLink}>
|
<div className={styles.calendarLink}>
|
||||||
|
@ -89,7 +89,7 @@ export const futureEventsQuery = graphql(`
|
|||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
export function getSingularEvents(events: EventFragment[]) {
|
export function getSingularEvents(events: EventFragment[]): SingularEvent[] {
|
||||||
return events
|
return events
|
||||||
.map((event) => {
|
.map((event) => {
|
||||||
return event.occurrences.map((occurrence) => {
|
return event.occurrences.map((occurrence) => {
|
||||||
@ -100,6 +100,12 @@ export function getSingularEvents(events: EventFragment[]) {
|
|||||||
})
|
})
|
||||||
.flat();
|
.flat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function sortSingularEvents(events: SingularEvent[]) {
|
||||||
|
return events.sort((a, b) =>
|
||||||
|
compareAsc(new Date(a.occurrence.start), new Date(b.occurrence.start))
|
||||||
|
);
|
||||||
|
}
|
||||||
interface EventsByDate {
|
interface EventsByDate {
|
||||||
[yearMonth: string]: {
|
[yearMonth: string]: {
|
||||||
[week: string]: {
|
[week: string]: {
|
||||||
@ -109,9 +115,7 @@ interface EventsByDate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function organizeEventsByDate(events: SingularEvent[]): EventsByDate {
|
export function organizeEventsByDate(events: SingularEvent[]): EventsByDate {
|
||||||
const sortedEvents = events.sort((a, b) =>
|
const sortedEvents = sortSingularEvents(events);
|
||||||
compareAsc(new Date(a.occurrence.start), new Date(b.occurrence.start))
|
|
||||||
);
|
|
||||||
|
|
||||||
const eventsByDate: EventsByDate = {};
|
const eventsByDate: EventsByDate = {};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user