59 lines
1.9 KiB
TypeScript
59 lines
1.9 KiB
TypeScript
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"
|
|
|
|
export default async function CurrentContentPage({
|
|
params,
|
|
searchParams,
|
|
}: PageArgs<LangParams, UriParams>) {
|
|
try {
|
|
ContentstackLivePreview.setConfigFromParams(searchParams)
|
|
|
|
if (!searchParams.uri) {
|
|
return <LoadingPreview />
|
|
}
|
|
|
|
const response = await previewRequest<GetCurrentBlockPageData>(
|
|
GetCurrentBlockPage,
|
|
{ locale: params.lang, uid: searchParams.uri }
|
|
)
|
|
|
|
if (!response.data?.all_current_blocks_page?.total) {
|
|
console.log("#### DATA ####")
|
|
console.log(response.data)
|
|
console.log("SearchParams URI: ", searchParams.uri)
|
|
throw new Error("Not found")
|
|
}
|
|
|
|
const page = response.data.all_current_blocks_page.items[0]
|
|
const images = page.hero?.imagesConnection
|
|
|
|
return (
|
|
<>
|
|
<Header lang={params.lang} pathname={searchParams.uri} />
|
|
{images?.totalCount ? <Hero images={images.edges} /> : null}
|
|
<main className="main l-sections-wrapper" id="maincontent" role="main">
|
|
<h1>{page.title}</h1>
|
|
<Blocks blocks={page.blocks} />
|
|
<Aside blocks={page.aside} />
|
|
</main>
|
|
</>
|
|
)
|
|
} catch (error) {
|
|
// TODO: throw 500
|
|
console.error(error)
|
|
throw new Error("Something went wrong")
|
|
}
|
|
}
|