-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dynamic page and display video paragraph
- Loading branch information
1 parent
515f9f2
commit 50baa47
Showing
15 changed files
with
177 additions
and
67 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { notFound } from "next/navigation" | ||
import React from "react" | ||
|
||
import BasicPageLayout from "@/components/pages/basicPageLayout/BasicPageLayout" | ||
import { fetcher } from "@/lib/graphql/fetchers/dpl-cms.fetcher" | ||
import { | ||
GetPageByPathDocument, | ||
GetPageByPathQuery, | ||
NodeGoPage, | ||
} from "@/lib/graphql/generated/dpl-cms/graphql" | ||
|
||
async function page(props: { params: Promise<{ slug: string[] }> }) { | ||
const params = await props.params | ||
|
||
const { slug } = params | ||
|
||
const data = await fetcher<GetPageByPathQuery, { path: string }>(GetPageByPathDocument, { | ||
path: slug.join("/"), | ||
})() | ||
|
||
const routeType = data.route?.__typename | ||
|
||
if (routeType === "RouteRedirect") { | ||
// TODO: implement redirect | ||
return | ||
} | ||
|
||
if (routeType === "RouteExternal") { | ||
// TODO: implement external route redirect | ||
return | ||
} | ||
|
||
if (!routeType || !data?.route?.entity) { | ||
return notFound() | ||
} | ||
|
||
const pageData = data.route.entity | ||
|
||
return <BasicPageLayout pageData={pageData as NodeGoPage} /> | ||
} | ||
|
||
export default page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from "react" | ||
|
||
import ParagraphVideo from "@/components/paragraphs/ParagraphGoVideo/ParagraphVideo" | ||
import ParagraphResolver from "@/components/paragraphs/ParagraphResolver" | ||
import { NodeGoPage, ParagraphUnion } from "@/lib/graphql/generated/dpl-cms/graphql" | ||
|
||
function BasicPageLayout({ pageData }: { pageData: NodeGoPage }) { | ||
const { paragraphs } = pageData | ||
|
||
return ( | ||
<div className="gap-y-paragraph-spacing flex flex-col"> | ||
<ParagraphResolver paragraphs={paragraphs ?? []} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default BasicPageLayout |
43 changes: 43 additions & 0 deletions
43
components/paragraphs/ParagraphGoVideo/ParagraphGoVideo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"use client" | ||
|
||
import React, { useEffect } from "react" | ||
|
||
import type { ParagraphGoVideo } from "@/lib/graphql/generated/dpl-cms/graphql" | ||
|
||
export default function ParagraphGoVideo(paragraphGoVideo: ParagraphGoVideo) { | ||
const [mounted, setMounted] = React.useState(false) | ||
|
||
useEffect(() => { | ||
setMounted(true) | ||
}, []) | ||
|
||
const { goVideoTitle: title } = paragraphGoVideo | ||
|
||
return ( | ||
<div className="content-container grid-go gap-paragraph-spacing-inner"> | ||
<div className="col-span-6 w-full lg:col-span-10 lg:col-start-2"> | ||
<h2 className="text-center text-typo-heading-2">{title}</h2> | ||
</div> | ||
|
||
<div className="col-span-6 lg:col-span-12"> | ||
{mounted && ( | ||
<div className="relative aspect-16/9 w-full overflow-hidden rounded-base"> | ||
<iframe | ||
aria-label="Naja Marie Aidt - Oevelser i moerke" | ||
className="absolute inset-0 h-full w-full" | ||
style={{ | ||
position: "absolute", | ||
top: 0, | ||
left: 0, | ||
width: "100%!important", | ||
height: "100%!important", | ||
}} | ||
src="https://media.videotool.dk/?vn=557_2024111913325696587632242634" | ||
allowFullScreen | ||
allow="autoplay; fullscreen"></iframe> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from "react" | ||
|
||
import { ParagraphUnion } from "@/lib/graphql/generated/dpl-cms/graphql" | ||
|
||
import ParagraphGoVideo from "./ParagraphGoVideo/ParagraphGoVideo" | ||
import { ParagraphErrorBoundary } from "./paragraphErrorBoundary/paragraphErrorBoundary" | ||
|
||
function ParagraphResolver({ paragraphs }: { paragraphs: ParagraphUnion[] }) { | ||
const components = { | ||
ParagraphGoVideo, | ||
} | ||
|
||
return paragraphs.map((paragraph, index) => { | ||
const type = paragraph?.__typename | ||
if (!type) { | ||
return null | ||
} | ||
|
||
const DynamicComponentType = components[type as keyof typeof components] || null | ||
|
||
return ( | ||
<ParagraphErrorBoundary key={index}> | ||
{DynamicComponentType ? <DynamicComponentType key={index} {...paragraph} /> : null} | ||
</ParagraphErrorBoundary> | ||
) | ||
}) | ||
} | ||
|
||
export default ParagraphResolver |
22 changes: 22 additions & 0 deletions
22
components/paragraphs/paragraphErrorBoundary/paragraphErrorBoundary.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use client" | ||
|
||
import { ErrorBoundary } from "react-error-boundary" | ||
|
||
import { Button } from "../../shared/button/Button" | ||
|
||
function ErrorFallback({ resetErrorBoundary }: { resetErrorBoundary: () => void }) { | ||
return ( | ||
<div className="bg-sand flex h-[200px] w-full flex-col items-center justify-center"> | ||
<p>Noget gik galt ved visning af denne blok - måske den mangler indhold?</p> | ||
<Button className="mt-4" onClick={resetErrorBoundary}> | ||
Genindlæs | ||
</Button> | ||
</div> | ||
) | ||
} | ||
|
||
function ParagraphErrorBoundary({ children }: { children: React.ReactNode }) { | ||
return <ErrorBoundary FallbackComponent={ErrorFallback}>{children}</ErrorBoundary> | ||
} | ||
|
||
export { ParagraphErrorBoundary } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters