diff --git a/web/src/components/blocks/Blocks.tsx b/web/src/components/blocks/Blocks.tsx index d0ccb35..28febbd 100644 --- a/web/src/components/blocks/Blocks.tsx +++ b/web/src/components/blocks/Blocks.tsx @@ -1,84 +1,168 @@ import dynamic from "next/dynamic"; -import { RichTextBlock } from "./RichTextBlock"; -import { ImageWithTextBlock } from "./ImageWithTextBlock"; -import { HorizontalRuleBlock } from "./HorizontalRuleBlock"; - -const ImageSliderBlock = dynamic(() => - import("./ImageSliderBlock").then((m) => m.ImageSliderBlock) -); -import { FeaturedBlock } from "./FeaturedBlock"; +import type { + AccordionBlockFragment, + ContactEntityBlockFragment, + ContactListBlockFragment, + ContactSectionBlockFragment, + ContactSubsectionBlockFragment, + EmbedBlockFragment, + FactBoxBlockFragment, + FeaturedBlockFragment, + HorizontalRuleBlockFragment, + ImageSliderBlockFragment, + ImageWithTextBlockFragment, + PageSectionBlockFragment, + RichTextBlockFragment, + ScheduleBlockFragment, +} from "@/gql/graphql"; import { AccordionBlock } from "./AccordionBlock"; +import { ContactEntityBlock } from "./ContactEntityBlock"; +import { ContactListBlock } from "./ContactListBlock"; +import { ContactSectionBlock, ContactSubsectionBlock } from "./ContactSection"; import { EmbedBlock } from "./EmbedBlock"; import { FactBoxBlock } from "./FactBoxBlock"; -import { ScheduleBlock } from "./ScheduleBlock"; -import { PageSectionBlock, PageSectionNavigationBlock } from "./PageSection"; -import { ContactSectionBlock, ContactSubsectionBlock } from "./ContactSection"; -import { ContactListBlock } from "./ContactListBlock"; -import { ContactEntityBlock } from "./ContactEntityBlock"; +import { FeaturedBlock } from "./FeaturedBlock"; +import { HorizontalRuleBlock } from "./HorizontalRuleBlock"; +import { ImageWithTextBlock } from "./ImageWithTextBlock"; import { NeufAddressSectionBlock } from "./NeufAddressSectionBlock"; import { OpeningHoursSectionBlock } from "./OpeningHoursSectionBlock"; +import { PageSectionBlock, PageSectionNavigationBlock } from "./PageSection"; +import { RichTextBlock } from "./RichTextBlock"; +import { ScheduleBlock } from "./ScheduleBlock"; -export const Blocks = ({ blocks, pageContent }: { blocks: any, pageContent?: boolean }) => { - const sections = blocks.filter( - (block: any) => block?.__typename === "PageSectionBlock" - ); +const ImageSliderBlock = dynamic(() => + import("./ImageSliderBlock").then((m) => m.ImageSliderBlock), +); - return blocks.map((block: any) => { - switch (block?.blockType) { +export type StreamFieldBlock = { + id?: string | null; + blockType?: string; + __typename?: string; + [key: string]: unknown; +}; + +export const Blocks = ({ + blocks, + pageContent, +}: { + blocks?: Array | null; + pageContent?: boolean; +}) => { + const sections = (blocks ?? []).filter( + (block) => block?.__typename === "PageSectionBlock", + ) as PageSectionBlockFragment[]; + + return (blocks ?? []).map((block) => { + if (!block) { + return null; + } + switch (block.blockType) { case "RichTextBlock": - return ; - break; + return ( + + ); case "ImageWithTextBlock": - return ; - break; - case "EmbedBlock": - return ; - break; + return ( + + ); + case "EmbedBlock": + return ( + + ); case "ImageSliderBlock": - return ; - break; + return ( + + ); case "HorizontalRuleBlock": - return ; - break; + return ( + + ); case "FeaturedBlock": - return ; - break; + return ( + + ); case "AccordionBlock": - return ; - break; + return ( + + ); case "FactBoxBlock": - return ; - break; + return ( + + ); case "ScheduleBlock": - return ; - break; + return ( + + ); case "PageSectionBlock": - return ; - break; + return ( + + ); case "PageSectionNavigationBlock": - return ; - break; + return ( + + ); case "ContactSectionBlock": - return ; - break; + return ( + + ); case "ContactSubsectionBlock": - return ; - break; + return ( + + ); case "ContactListBlock": - return ; - break; + return ( + + ); case "ContactEntityBlock": - return ; - break; + return ( + + ); case "NeufAddressSectionBlock": - return ; - break; + return ; case "OpeningHoursSectionBlock": - return ; - break; + return ; default: console.log("unsupported block", block); - return
Unsupported block type {block?.blockType}
; + return ( +
Unsupported block type {block.blockType}
+ ); } }); }; diff --git a/web/src/components/general/PageContent.tsx b/web/src/components/general/PageContent.tsx index a62cef9..8ab6be6 100644 --- a/web/src/components/general/PageContent.tsx +++ b/web/src/components/general/PageContent.tsx @@ -1,7 +1,13 @@ -import { Blocks } from "@/components/blocks/Blocks"; +import { Blocks, type StreamFieldBlock } from "@/components/blocks/Blocks"; import styles from './pageContent.module.scss'; -export const PageContent = ({ blocks, className }: { blocks: any; className?: string }) => { +export const PageContent = ({ + blocks, + className, +}: { + blocks?: Array | null; + className?: string; +}) => { return (