From c8a37b22da52fd6f49121f1db4ff350926f48804 Mon Sep 17 00:00:00 2001 From: Christel Westerberg Date: Mon, 12 Feb 2024 15:58:23 +0100 Subject: [PATCH 1/2] fix: breakout current page tsx --- .../(live)/current-content-page/page.tsx | 46 +++------------- app/[lang]/(preview)/preview/page.tsx | 27 +++------- components/Current/ContentPage/index.tsx | 53 +++++++++++++++++++ 3 files changed, 66 insertions(+), 60 deletions(-) create mode 100644 components/Current/ContentPage/index.tsx diff --git a/app/[lang]/(live)/current-content-page/page.tsx b/app/[lang]/(live)/current-content-page/page.tsx index 71feae069..2585f6982 100644 --- a/app/[lang]/(live)/current-content-page/page.tsx +++ b/app/[lang]/(live)/current-content-page/page.tsx @@ -3,13 +3,7 @@ import { notFound } from "next/navigation" import { request } from "@/lib/request"; import { GetCurrentBlockPage } from "@/lib/graphql/Query/CurrentBlockPage.graphql"; -import Aside from "@/components/Current/Aside" -import Blocks from "@/components/Current/Blocks" -import Header from "@/components/Current/Header" -import Hero from "@/components/Current/Hero" -import Preamble from "@/components/Current/Preamble" -import Section from "@/components/Current/Section" -import SubnavMobile from "@/components/Current/SubnavMobile" +import ContentPage from "@/components/Current/ContentPage" import type { PageArgs, LangParams, UriParams } from "@/types/params" import type { GetCurrentBlockPageData } from "@/types/requests/currentBlockPage" @@ -38,40 +32,12 @@ export default async function CurrentContentPage({ throw new Error("Not found") } - const page = response.data.all_current_blocks_page.items[0] - const images = page.hero?.imagesConnection - const breadcrumbs = page.breadcrumbs.parentsConnection - const parent = breadcrumbs.edges.at(-1) - return ( - <> -
- {images?.totalCount ? : null} -
- - - -
- -
-
- + ) } catch (err) { return notFound() diff --git a/app/[lang]/(preview)/preview/page.tsx b/app/[lang]/(preview)/preview/page.tsx index 1d63fdd34..a94eb2107 100644 --- a/app/[lang]/(preview)/preview/page.tsx +++ b/app/[lang]/(preview)/preview/page.tsx @@ -1,17 +1,11 @@ -import { notFound } from "next/navigation" - import { previewRequest } from "@/lib/previewRequest" import { GetCurrentBlockPage } from "@/lib/graphql/Query/CurrentBlockPage.graphql" -import Aside from "@/components/Current/Aside" -import Blocks from "@/components/Current/Blocks" -import Header from "@/components/Current/Header" -import Hero from "@/components/Current/Hero" - import type { PageArgs, LangParams, UriParams } from "@/types/params" import type { GetCurrentBlockPageData } from "@/types/requests/currentBlockPage" import ContentstackLivePreview from "@contentstack/live-preview-utils" import LoadingPreview from "@/components/Current/LoadingPreview" +import ContentPage from "@/components/Current/ContentPage" export default async function CurrentContentPage({ params, @@ -26,7 +20,7 @@ export default async function CurrentContentPage({ const response = await previewRequest( GetCurrentBlockPage, - { locale: params.lang, uid: searchParams.uri } + { locale: params.lang, uri: searchParams.uri } ) if (!response.data?.all_current_blocks_page?.total) { @@ -36,19 +30,12 @@ export default async function CurrentContentPage({ throw new Error("Not found") } - const page = response.data.all_current_blocks_page.items[0] - const images = page.hero?.imagesConnection - return ( - <> -
- {images?.totalCount ? : null} -
-

{page.title}

- -
- + ) } catch (error) { // TODO: throw 500 diff --git a/components/Current/ContentPage/index.tsx b/components/Current/ContentPage/index.tsx new file mode 100644 index 000000000..a950410b1 --- /dev/null +++ b/components/Current/ContentPage/index.tsx @@ -0,0 +1,53 @@ +import Aside from "@/components/Current/Aside" +import Blocks from "@/components/Current/Blocks" +import Header from "@/components/Current/Header" +import Hero from "@/components/Current/Hero" +import Preamble from "@/components/Current/Preamble" +import Section from "@/components/Current/Section" +import SubnavMobile from "@/components/Current/SubnavMobile" +import { Lang } from "@/types/lang" +import { GetCurrentBlockPageData } from "@/types/requests/currentBlockPage" + +type ContentPageProps = { + data: GetCurrentBlockPageData + uri: string + lang: Lang +} + +export default function ContentPage({ data, lang, uri }: ContentPageProps) { + const page = data.all_current_blocks_page.items[0] + const images = page.hero?.imagesConnection + const breadcrumbs = page.breadcrumbs.parentsConnection + const parent = breadcrumbs.edges.at(-1) + + return ( + <> +
+ {images?.totalCount ? : null} +
+ + + +
+ +
+
+ + ) +} From 12b5a131e78dd9820bf7eeb76a53b4c9e67132ba Mon Sep 17 00:00:00 2001 From: Christel Westerberg Date: Mon, 12 Feb 2024 16:03:59 +0100 Subject: [PATCH 2/2] fix: breakout typings --- components/Current/ContentPage/index.tsx | 9 ++------- types/components/current/contentPage.ts | 8 ++++++++ 2 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 types/components/current/contentPage.ts diff --git a/components/Current/ContentPage/index.tsx b/components/Current/ContentPage/index.tsx index a950410b1..dffebd2b6 100644 --- a/components/Current/ContentPage/index.tsx +++ b/components/Current/ContentPage/index.tsx @@ -5,14 +5,9 @@ import Hero from "@/components/Current/Hero" import Preamble from "@/components/Current/Preamble" import Section from "@/components/Current/Section" import SubnavMobile from "@/components/Current/SubnavMobile" -import { Lang } from "@/types/lang" -import { GetCurrentBlockPageData } from "@/types/requests/currentBlockPage" -type ContentPageProps = { - data: GetCurrentBlockPageData - uri: string - lang: Lang -} +import type { ContentPageProps } from "@/types/components/current/contentPage" + export default function ContentPage({ data, lang, uri }: ContentPageProps) { const page = data.all_current_blocks_page.items[0] diff --git a/types/components/current/contentPage.ts b/types/components/current/contentPage.ts new file mode 100644 index 000000000..73f029864 --- /dev/null +++ b/types/components/current/contentPage.ts @@ -0,0 +1,8 @@ +import type { Lang } from "@/types/lang" +import type { GetCurrentBlockPageData } from "@/types/requests/currentBlockPage" + +export type ContentPageProps = { + data: GetCurrentBlockPageData + uri: string + lang: Lang +}