simplify some type checks by fixing graphql schema
This commit is contained in:
@ -10,11 +10,7 @@ import {
|
||||
} from "date-fns";
|
||||
import { toLocalTime, formatDate } from "./date";
|
||||
import { graphql } from "@/gql";
|
||||
import {
|
||||
EventFragment,
|
||||
EventCategory,
|
||||
EventOccurrence,
|
||||
} from "@/gql/graphql";
|
||||
import { EventFragment, EventCategory, EventOccurrence } from "@/gql/graphql";
|
||||
|
||||
export type {
|
||||
EventFragment,
|
||||
@ -94,22 +90,14 @@ export const allEventsQuery = graphql(`
|
||||
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;
|
||||
});
|
||||
return event.occurrences.map((occurrence) => {
|
||||
const eventOccurrence: any = structuredClone(event);
|
||||
eventOccurrence.occurrence = occurrence;
|
||||
return eventOccurrence;
|
||||
});
|
||||
})
|
||||
.flat()
|
||||
.filter((x): x is SingularEvent => isDefined(x));
|
||||
.flat();
|
||||
}
|
||||
|
||||
function isDefined<T>(val: T | undefined | null): val is T {
|
||||
return val !== undefined && val !== null;
|
||||
}
|
||||
|
||||
interface EventsByDate {
|
||||
[yearMonth: string]: {
|
||||
[week: string]: {
|
||||
|
Reference in New Issue
Block a user