reorganize some event queries, types and components

This commit is contained in:
2024-05-12 00:01:12 +02:00
parent bc9fbd5d84
commit a6fcaa1579
8 changed files with 154 additions and 122 deletions

77
web/src/lib/event.ts Normal file
View File

@ -0,0 +1,77 @@
import { graphql } from "@/gql";
import { EventFragment, EventOccurrence } from "@/gql/graphql";
const EventFragmentDefinition = graphql(`
fragment Event on EventPage {
__typename
id
slug
title
body {
id
blockType
field
... on RichTextBlock {
rawValue
value
}
}
featuredImage {
url
width
height
}
facebookUrl
ticketUrl
priceRegular
priceMember
priceStudent
occurrences {
... on EventOccurrence {
__typename
id
start
end
venue {
__typename
id
slug
title
}
}
}
}
`);
export const allEventsQuery = graphql(`
query allEvents {
events: pages(contentType: "events.EventPage") {
... on EventPage {
...Event
}
}
}
`);
export type SingularEvent = EventFragment & {
occurrence: EventOccurrence;
};
export function getSingularEvents(events: EventFragment[]) {
return events
.map((event) => {
return event.occurrences
?.filter((x): x is EventOccurrence => isDefined(x))
.map((occurrence) => {
const eventOccurrence = structuredClone(event);
eventOccurrence.occurrence = occurrence;
return eventOccurrence;
});
})
.flat()
.filter((x): x is SingularEvent => isDefined(x));
}
function isDefined<T>(val: T | undefined | null): val is T {
return val !== undefined && val !== null;
}