reorganize some event queries, types and components
This commit is contained in:
77
web/src/lib/event.ts
Normal file
77
web/src/lib/event.ts
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user