From 08b2e5387d4e0f3c85362f0801008d1f727bb9a9 Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Tue, 14 May 2024 19:07:41 +0200 Subject: [PATCH] fix some type errors --- web/src/app/arrangementer/page.tsx | 5 +- web/src/components/events/EventContainer.tsx | 15 +- web/src/components/events/EventHeader.tsx | 8 +- web/src/components/news/NewsList.tsx | 6 +- web/src/gql/graphql.ts | 193 ++++++++++++++++--- web/src/lib/event.ts | 4 +- 6 files changed, 189 insertions(+), 42 deletions(-) diff --git a/web/src/app/arrangementer/page.tsx b/web/src/app/arrangementer/page.tsx index 08e159d..08453c2 100644 --- a/web/src/app/arrangementer/page.tsx +++ b/web/src/app/arrangementer/page.tsx @@ -3,7 +3,7 @@ import { EventContainer } from "@/components/events/EventContainer"; import { allEventsQuery, EventFragment, - EventCategoryFragment, + EventCategory, EventOccurrence, } from "@/lib/event"; import { PageHeader } from "@/components/general/PageHeader"; @@ -11,8 +11,7 @@ import { PageHeader } from "@/components/general/PageHeader"; export default async function Page() { const { data, error } = await getClient().query(allEventsQuery, {}); const events = (data?.events ?? []) as EventFragment[]; - const eventCategories = (data?.eventCategories ?? - []) as EventCategoryFragment[]; + const eventCategories = (data?.eventCategories ?? []) as EventCategory[]; return (
diff --git a/web/src/components/events/EventContainer.tsx b/web/src/components/events/EventContainer.tsx index a48d562..286d7a8 100644 --- a/web/src/components/events/EventContainer.tsx +++ b/web/src/components/events/EventContainer.tsx @@ -5,7 +5,7 @@ import { EventItem } from "./EventItem"; import { EventFilter } from "./EventFilter"; import { EventFragment, - EventCategoryFragment, + EventCategory, SingularEvent, getSingularEvents, organizeEventsByDate, @@ -24,7 +24,7 @@ export const EventContainer = ({ eventCategories, }: { events: EventFragment[]; - eventCategories: EventCategoryFragment[]; + eventCategories: EventCategory[]; }) => { const [mode, setMode] = useQueryState( "mode", @@ -32,18 +32,21 @@ export const EventContainer = ({ ); const filterableCategories = eventCategories.filter((x) => x.showInFilters); + const filterableCategorySlugs: string[] = filterableCategories + .filter((x) => "slug" in x && typeof x.slug === "string") + .map((x) => x.slug); + const [category, setCategory] = useQueryState( "category", - parseAsStringLiteral(filterableCategories.map((x) => x.slug)).withDefault( - null - ) + parseAsStringLiteral(filterableCategorySlugs).withDefault(null) ); const filteredEvents = events.filter( (x) => !category || x.categories - ?.map((eventCategory) => eventCategory.slug) + ?.filter((x) => x !== null) + .map((eventCategory: EventCategory) => eventCategory.slug) .includes(category) ); diff --git a/web/src/components/events/EventHeader.tsx b/web/src/components/events/EventHeader.tsx index 912cde1..1263a5c 100644 --- a/web/src/components/events/EventHeader.tsx +++ b/web/src/components/events/EventHeader.tsx @@ -1,4 +1,4 @@ -import { EventFragment } from "@/gql/graphql"; +import { EventCategory, EventFragment } from "@/lib/event"; import styles from "./eventHeader.module.scss"; import Image from "@/components/general/Image"; import { Pig } from "../general/Pig"; @@ -16,7 +16,11 @@ export const EventHeader = ({ event }: { event: EventFragment }) => {
Medlemspris: {event.priceMember}
Kategorier:{" "} - {event.categories && event.categories.map((x) => x.name).join(", ")} + {event.categories && + event.categories + .filter((x) => x != null) + .map((x: EventCategoryFragment) => x.name) + .join(", ")}
diff --git a/web/src/components/news/NewsList.tsx b/web/src/components/news/NewsList.tsx index 1e12add..1f5d2c1 100644 --- a/web/src/components/news/NewsList.tsx +++ b/web/src/components/news/NewsList.tsx @@ -6,9 +6,9 @@ export const NewsList = ({ featured, limit, }: { - heading: string; - featured: boolean; - limit: number; + heading?: string; + featured?: boolean; + limit?: number; }) => { return (
diff --git a/web/src/gql/graphql.ts b/web/src/gql/graphql.ts index ee51b06..05bd40d 100644 --- a/web/src/gql/graphql.ts +++ b/web/src/gql/graphql.ts @@ -36,12 +36,13 @@ export type Scalars = { UUID: { input: any; output: any; } }; -export type Association = PageInterface & { - __typename?: 'Association'; +export type AssociationIndex = PageInterface & { + __typename?: 'AssociationIndex'; aliasOf?: Maybe; aliases: Array; ancestors: Array; - association?: Maybe; + associationindex?: Maybe; + associationpage?: Maybe; children: Array; contentType: Scalars['String']['output']; depth?: Maybe; @@ -84,7 +85,7 @@ export type Association = PageInterface & { }; -export type AssociationAncestorsArgs = { +export type AssociationIndexAncestorsArgs = { id?: InputMaybe; limit?: InputMaybe; offset?: InputMaybe; @@ -93,7 +94,7 @@ export type AssociationAncestorsArgs = { }; -export type AssociationChildrenArgs = { +export type AssociationIndexChildrenArgs = { id?: InputMaybe; limit?: InputMaybe; offset?: InputMaybe; @@ -102,7 +103,7 @@ export type AssociationChildrenArgs = { }; -export type AssociationDescendantsArgs = { +export type AssociationIndexDescendantsArgs = { id?: InputMaybe; limit?: InputMaybe; offset?: InputMaybe; @@ -111,7 +112,7 @@ export type AssociationDescendantsArgs = { }; -export type AssociationNextSiblingsArgs = { +export type AssociationIndexNextSiblingsArgs = { id?: InputMaybe; limit?: InputMaybe; offset?: InputMaybe; @@ -120,7 +121,7 @@ export type AssociationNextSiblingsArgs = { }; -export type AssociationPreviousSiblingsArgs = { +export type AssociationIndexPreviousSiblingsArgs = { id?: InputMaybe; limit?: InputMaybe; offset?: InputMaybe; @@ -129,7 +130,109 @@ export type AssociationPreviousSiblingsArgs = { }; -export type AssociationSiblingsArgs = { +export type AssociationIndexSiblingsArgs = { + id?: InputMaybe; + limit?: InputMaybe; + offset?: InputMaybe; + order?: InputMaybe; + searchQuery?: InputMaybe; +}; + +export type AssociationPage = PageInterface & { + __typename?: 'AssociationPage'; + aliasOf?: Maybe; + aliases: Array; + ancestors: Array; + associationindex?: Maybe; + associationpage?: Maybe; + children: Array; + contentType: Scalars['String']['output']; + depth?: Maybe; + descendants: Array; + draftTitle: Scalars['String']['output']; + eventindex?: Maybe; + eventpage?: Maybe; + expireAt?: Maybe; + expired: Scalars['Boolean']['output']; + firstPublishedAt?: Maybe; + genericpage?: Maybe; + goLiveAt?: Maybe; + hasUnpublishedChanges: Scalars['Boolean']['output']; + homepage?: Maybe; + id?: Maybe; + lastPublishedAt?: Maybe; + latestRevisionCreatedAt?: Maybe; + live: Scalars['Boolean']['output']; + locked?: Maybe; + lockedAt?: Maybe; + nextSiblings: Array; + numchild: Scalars['Int']['output']; + pageType?: Maybe; + parent?: Maybe; + path: Scalars['String']['output']; + previousSiblings: Array; + searchDescription?: Maybe; + searchScore?: Maybe; + seoTitle: Scalars['String']['output']; + showInMenus: Scalars['Boolean']['output']; + siblings: Array; + sitesRootedHere: Array; + slug: Scalars['String']['output']; + title: Scalars['String']['output']; + translationKey: Scalars['UUID']['output']; + url?: Maybe; + urlPath: Scalars['String']['output']; + venueindex?: Maybe; + venuepage?: Maybe; +}; + + +export type AssociationPageAncestorsArgs = { + id?: InputMaybe; + limit?: InputMaybe; + offset?: InputMaybe; + order?: InputMaybe; + searchQuery?: InputMaybe; +}; + + +export type AssociationPageChildrenArgs = { + id?: InputMaybe; + limit?: InputMaybe; + offset?: InputMaybe; + order?: InputMaybe; + searchQuery?: InputMaybe; +}; + + +export type AssociationPageDescendantsArgs = { + id?: InputMaybe; + limit?: InputMaybe; + offset?: InputMaybe; + order?: InputMaybe; + searchQuery?: InputMaybe; +}; + + +export type AssociationPageNextSiblingsArgs = { + id?: InputMaybe; + limit?: InputMaybe; + offset?: InputMaybe; + order?: InputMaybe; + searchQuery?: InputMaybe; +}; + + +export type AssociationPagePreviousSiblingsArgs = { + id?: InputMaybe; + limit?: InputMaybe; + offset?: InputMaybe; + order?: InputMaybe; + searchQuery?: InputMaybe; +}; + + +export type AssociationPageSiblingsArgs = { id?: InputMaybe; limit?: InputMaybe; offset?: InputMaybe; @@ -289,7 +392,8 @@ export type EventIndex = PageInterface & { aliasOf?: Maybe; aliases: Array; ancestors: Array; - association?: Maybe; + associationindex?: Maybe; + associationpage?: Maybe; children: Array; contentType: Scalars['String']['output']; depth?: Maybe; @@ -393,12 +497,18 @@ export type EventOccurrence = { venue?: Maybe; }; +export type EventOrganizer = { + __typename?: 'EventOrganizer'; + id?: Maybe; +}; + export type EventPage = PageInterface & { __typename?: 'EventPage'; aliasOf?: Maybe; aliases: Array; ancestors: Array; - association?: Maybe; + associationindex?: Maybe; + associationpage?: Maybe; body?: Maybe>>; categories?: Maybe>>; children: Array; @@ -426,6 +536,7 @@ export type EventPage = PageInterface & { nextSiblings: Array; numchild: Scalars['Int']['output']; occurrences?: Maybe>>; + organizers?: Maybe>>; pageType?: Maybe; parent?: Maybe; path: Scalars['String']['output']; @@ -504,6 +615,15 @@ export type EventPageOccurrencesArgs = { }; +export type EventPageOrganizersArgs = { + id?: InputMaybe; + limit?: InputMaybe; + offset?: InputMaybe; + order?: InputMaybe; + searchQuery?: InputMaybe; +}; + + export type EventPagePreviousSiblingsArgs = { id?: InputMaybe; limit?: InputMaybe; @@ -535,7 +655,8 @@ export type GenericPage = PageInterface & { aliasOf?: Maybe; aliases: Array; ancestors: Array; - association?: Maybe; + associationindex?: Maybe; + associationpage?: Maybe; body?: Maybe>>; children: Array; contentType: Scalars['String']['output']; @@ -637,7 +758,8 @@ export type HomePage = PageInterface & { aliasOf?: Maybe; aliases: Array; ancestors: Array; - association?: Maybe; + associationindex?: Maybe; + associationpage?: Maybe; children: Array; contentType: Scalars['String']['output']; depth?: Maybe; @@ -832,7 +954,8 @@ export type Page = PageInterface & { aliasOf?: Maybe; aliases: Array; ancestors: Array; - association?: Maybe; + associationindex?: Maybe; + associationpage?: Maybe; children: Array; contentType: Scalars['String']['output']; depth?: Maybe; @@ -1049,6 +1172,8 @@ export type Query = { documents: Array; eventCategories?: Maybe>>; eventCategory?: Maybe; + eventOrganizer?: Maybe; + eventOrganizers?: Maybe>>; image?: Maybe; imageType: Scalars['String']['output']; images: Array; @@ -1100,6 +1225,20 @@ export type QueryEventCategoryArgs = { }; +export type QueryEventOrganizerArgs = { + id?: InputMaybe; +}; + + +export type QueryEventOrganizersArgs = { + id?: InputMaybe; + limit?: InputMaybe; + offset?: InputMaybe; + order?: InputMaybe; + searchQuery?: InputMaybe; +}; + + export type QueryImageArgs = { id?: InputMaybe; }; @@ -1209,7 +1348,7 @@ export type RichTextBlock = StreamFieldInterface & { value: Scalars['String']['output']; }; -export type Search = Association | EventCategory | EventIndex | EventOccurrence | EventPage | GenericPage | HomePage | Page | VenueIndex | VenuePage; +export type Search = AssociationIndex | AssociationPage | EventCategory | EventIndex | EventOccurrence | EventOrganizer | EventPage | GenericPage | HomePage | Page | VenueIndex | VenuePage; export type SiteObjectType = { __typename?: 'SiteObjectType'; @@ -1331,7 +1470,8 @@ export type VenueIndex = PageInterface & { aliasOf?: Maybe; aliases: Array; ancestors: Array; - association?: Maybe; + associationindex?: Maybe; + associationpage?: Maybe; children: Array; contentType: Scalars['String']['output']; depth?: Maybe; @@ -1432,7 +1572,8 @@ export type VenuePage = PageInterface & { aliasOf?: Maybe; aliases: Array; ancestors: Array; - association?: Maybe; + associationindex?: Maybe; + associationpage?: Maybe; body?: Maybe>>; capabilityAudio?: Maybe; capabilityAudioVideo?: Maybe; @@ -1545,14 +1686,14 @@ export type GenericFragment = { __typename: 'GenericPage', id?: string | null, u export type AllGenericSlugsQueryVariables = Exact<{ [key: string]: never; }>; -export type AllGenericSlugsQuery = { __typename?: 'Query', pages: Array<{ __typename?: 'Association', id?: string | null, urlPath: string } | { __typename?: 'EventIndex', id?: string | null, urlPath: string } | { __typename?: 'EventPage', id?: string | null, urlPath: string } | { __typename?: 'GenericPage', id?: string | null, urlPath: string } | { __typename?: 'HomePage', id?: string | null, urlPath: string } | { __typename?: 'Page', id?: string | null, urlPath: string } | { __typename?: 'VenueIndex', id?: string | null, urlPath: string } | { __typename?: 'VenuePage', id?: string | null, urlPath: string }> }; +export type AllGenericSlugsQuery = { __typename?: 'Query', pages: Array<{ __typename?: 'AssociationIndex', id?: string | null, urlPath: string } | { __typename?: 'AssociationPage', id?: string | null, urlPath: string } | { __typename?: 'EventIndex', id?: string | null, urlPath: string } | { __typename?: 'EventPage', id?: string | null, urlPath: string } | { __typename?: 'GenericPage', id?: string | null, urlPath: string } | { __typename?: 'HomePage', id?: string | null, urlPath: string } | { __typename?: 'Page', id?: string | null, urlPath: string } | { __typename?: 'VenueIndex', id?: string | null, urlPath: string } | { __typename?: 'VenuePage', id?: string | null, urlPath: string }> }; export type GenericPageByUrlQueryVariables = Exact<{ urlPath: Scalars['String']['input']; }>; -export type GenericPageByUrlQuery = { __typename?: 'Query', page?: { __typename?: 'Association' } | { __typename?: 'EventIndex' } | { __typename?: 'EventPage' } | ( +export type GenericPageByUrlQuery = { __typename?: 'Query', page?: { __typename?: 'AssociationIndex' } | { __typename?: 'AssociationPage' } | { __typename?: 'EventIndex' } | { __typename?: 'EventPage' } | ( { __typename?: 'GenericPage' } & { ' $fragmentRefs'?: { 'GenericFragment': GenericFragment } } ) | { __typename?: 'HomePage' } | { __typename?: 'Page' } | { __typename?: 'VenueIndex' } | { __typename?: 'VenuePage' } | null }; @@ -1560,14 +1701,14 @@ export type GenericPageByUrlQuery = { __typename?: 'Query', page?: { __typename? export type AllEventSlugsQueryVariables = Exact<{ [key: string]: never; }>; -export type AllEventSlugsQuery = { __typename?: 'Query', pages: Array<{ __typename?: 'Association', id?: string | null, slug: string } | { __typename?: 'EventIndex', id?: string | null, slug: string } | { __typename?: 'EventPage', id?: string | null, slug: string } | { __typename?: 'GenericPage', id?: string | null, slug: string } | { __typename?: 'HomePage', id?: string | null, slug: string } | { __typename?: 'Page', id?: string | null, slug: string } | { __typename?: 'VenueIndex', id?: string | null, slug: string } | { __typename?: 'VenuePage', id?: string | null, slug: string }> }; +export type AllEventSlugsQuery = { __typename?: 'Query', pages: Array<{ __typename?: 'AssociationIndex', id?: string | null, slug: string } | { __typename?: 'AssociationPage', id?: string | null, slug: string } | { __typename?: 'EventIndex', id?: string | null, slug: string } | { __typename?: 'EventPage', id?: string | null, slug: string } | { __typename?: 'GenericPage', id?: string | null, slug: string } | { __typename?: 'HomePage', id?: string | null, slug: string } | { __typename?: 'Page', id?: string | null, slug: string } | { __typename?: 'VenueIndex', id?: string | null, slug: string } | { __typename?: 'VenuePage', id?: string | null, slug: string }> }; export type EventBySlugQueryVariables = Exact<{ slug: Scalars['String']['input']; }>; -export type EventBySlugQuery = { __typename?: 'Query', event?: { __typename?: 'Association' } | { __typename?: 'EventIndex' } | ( +export type EventBySlugQuery = { __typename?: 'Query', event?: { __typename?: 'AssociationIndex' } | { __typename?: 'AssociationPage' } | { __typename?: 'EventIndex' } | ( { __typename?: 'EventPage' } & { ' $fragmentRefs'?: { 'EventFragment': EventFragment } } ) | { __typename?: 'GenericPage' } | { __typename?: 'HomePage' } | { __typename?: 'Page' } | { __typename?: 'VenueIndex' } | { __typename?: 'VenuePage' } | null }; @@ -1575,14 +1716,14 @@ export type EventBySlugQuery = { __typename?: 'Query', event?: { __typename?: 'A export type AllVenueSlugsQueryVariables = Exact<{ [key: string]: never; }>; -export type AllVenueSlugsQuery = { __typename?: 'Query', pages: Array<{ __typename?: 'Association', id?: string | null, slug: string } | { __typename?: 'EventIndex', id?: string | null, slug: string } | { __typename?: 'EventPage', id?: string | null, slug: string } | { __typename?: 'GenericPage', id?: string | null, slug: string } | { __typename?: 'HomePage', id?: string | null, slug: string } | { __typename?: 'Page', id?: string | null, slug: string } | { __typename?: 'VenueIndex', id?: string | null, slug: string } | { __typename?: 'VenuePage', id?: string | null, slug: string }> }; +export type AllVenueSlugsQuery = { __typename?: 'Query', pages: Array<{ __typename?: 'AssociationIndex', id?: string | null, slug: string } | { __typename?: 'AssociationPage', id?: string | null, slug: string } | { __typename?: 'EventIndex', id?: string | null, slug: string } | { __typename?: 'EventPage', id?: string | null, slug: string } | { __typename?: 'GenericPage', id?: string | null, slug: string } | { __typename?: 'HomePage', id?: string | null, slug: string } | { __typename?: 'Page', id?: string | null, slug: string } | { __typename?: 'VenueIndex', id?: string | null, slug: string } | { __typename?: 'VenuePage', id?: string | null, slug: string }> }; export type VenueBySlugQueryVariables = Exact<{ slug: Scalars['String']['input']; }>; -export type VenueBySlugQuery = { __typename?: 'Query', venue?: { __typename?: 'Association' } | { __typename?: 'EventIndex' } | { __typename?: 'EventPage' } | { __typename?: 'GenericPage' } | { __typename?: 'HomePage' } | { __typename?: 'Page' } | { __typename?: 'VenueIndex' } | ( +export type VenueBySlugQuery = { __typename?: 'Query', venue?: { __typename?: 'AssociationIndex' } | { __typename?: 'AssociationPage' } | { __typename?: 'EventIndex' } | { __typename?: 'EventPage' } | { __typename?: 'GenericPage' } | { __typename?: 'HomePage' } | { __typename?: 'Page' } | { __typename?: 'VenueIndex' } | ( { __typename?: 'VenuePage' } & { ' $fragmentRefs'?: { 'VenueFragment': VenueFragment } } ) | null }; @@ -1592,7 +1733,7 @@ export type VenueFragment = { __typename: 'VenuePage', id?: string | null, slug: export type AllVenuesQueryVariables = Exact<{ [key: string]: never; }>; -export type AllVenuesQuery = { __typename?: 'Query', venues: Array<{ __typename?: 'Association' } | { __typename?: 'EventIndex' } | { __typename?: 'EventPage' } | { __typename?: 'GenericPage' } | { __typename?: 'HomePage' } | { __typename?: 'Page' } | { __typename?: 'VenueIndex' } | ( +export type AllVenuesQuery = { __typename?: 'Query', venues: Array<{ __typename?: 'AssociationIndex' } | { __typename?: 'AssociationPage' } | { __typename?: 'EventIndex' } | { __typename?: 'EventPage' } | { __typename?: 'GenericPage' } | { __typename?: 'HomePage' } | { __typename?: 'Page' } | { __typename?: 'VenueIndex' } | ( { __typename?: 'VenuePage' } & { ' $fragmentRefs'?: { 'VenueFragment': VenueFragment } } )> }; @@ -1600,7 +1741,7 @@ export type AllVenuesQuery = { __typename?: 'Query', venues: Array<{ __typename? export type HomeQueryVariables = Exact<{ [key: string]: never; }>; -export type HomeQuery = { __typename?: 'Query', events: Array<{ __typename?: 'Association' } | { __typename?: 'EventIndex' } | ( +export type HomeQuery = { __typename?: 'Query', events: Array<{ __typename?: 'AssociationIndex' } | { __typename?: 'AssociationPage' } | { __typename?: 'EventIndex' } | ( { __typename?: 'EventPage' } & { ' $fragmentRefs'?: { 'EventFragment': EventFragment } } ) | { __typename?: 'GenericPage' } | { __typename?: 'HomePage' } | { __typename?: 'Page' } | { __typename?: 'VenueIndex' } | { __typename?: 'VenuePage' }> }; @@ -1610,7 +1751,7 @@ export type EventFragment = { __typename: 'EventPage', id?: string | null, slug: export type AllEventsQueryVariables = Exact<{ [key: string]: never; }>; -export type AllEventsQuery = { __typename?: 'Query', events: Array<{ __typename?: 'Association' } | { __typename?: 'EventIndex' } | ( +export type AllEventsQuery = { __typename?: 'Query', events: Array<{ __typename?: 'AssociationIndex' } | { __typename?: 'AssociationPage' } | { __typename?: 'EventIndex' } | ( { __typename?: 'EventPage' } & { ' $fragmentRefs'?: { 'EventFragment': EventFragment } } ) | { __typename?: 'GenericPage' } | { __typename?: 'HomePage' } | { __typename?: 'Page' } | { __typename?: 'VenueIndex' } | { __typename?: 'VenuePage' }>, eventCategories?: Array<{ __typename?: 'EventCategory', name?: string | null, slug?: string | null, showInFilters?: boolean | null } | null> | null }; diff --git a/web/src/lib/event.ts b/web/src/lib/event.ts index a7f5bb3..0211e89 100644 --- a/web/src/lib/event.ts +++ b/web/src/lib/event.ts @@ -12,13 +12,13 @@ import { toLocalTime, formatDate } from "./date"; import { graphql } from "@/gql"; import { EventFragment, - EventCategoryFragment, + EventCategory, EventOccurrence, } from "@/gql/graphql"; export type { EventFragment, - EventCategoryFragment, + EventCategory, EventOccurrence, } from "@/gql/graphql";