feat: graphql client with fetches for initial pages
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
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 type { PageArgs, LangParams, UriParams } from "@/types/params";
|
||||
import type { GetCurrentBlockPageData } from "@/types/requests/currentBlockPage";
|
||||
|
||||
export default async function CurrentContentPage({
|
||||
params,
|
||||
@@ -15,39 +20,30 @@ export default async function CurrentContentPage({
|
||||
throw new Error("Bad URI");
|
||||
}
|
||||
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
"mockCms",
|
||||
params.lang,
|
||||
searchParams.uri,
|
||||
"data.json"
|
||||
);
|
||||
const response = await request<GetCurrentBlockPageData>(GetCurrentBlockPage, { locale: params.lang, url: searchParams.uri })
|
||||
|
||||
const data = await fs.readFile(filePath, { encoding: "utf-8" });
|
||||
|
||||
if (!data) {
|
||||
throw new Error("No data");
|
||||
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 json = JSON.parse(data);
|
||||
const page = response.data.all_current_blocks_page.items[0]
|
||||
const images = page.hero?.imagesConnection
|
||||
|
||||
return (
|
||||
<>
|
||||
<Header lang={params.lang} pathname={searchParams.uri} />
|
||||
{json.hero ? (
|
||||
<div
|
||||
dangerouslySetInnerHTML={{ __html: json.hero }}
|
||||
className="hero-content-overlay hero-content-widget"
|
||||
/>
|
||||
) : null}
|
||||
{json.content ? (
|
||||
<main
|
||||
className="main l-sections-wrapper"
|
||||
role="main"
|
||||
id="maincontent"
|
||||
dangerouslySetInnerHTML={{ __html: json.content }}
|
||||
/>
|
||||
) : null}
|
||||
{images?.totalCount ? <Hero images={images.edges} /> : null}
|
||||
<main
|
||||
className="main l-sections-wrapper"
|
||||
id="maincontent"
|
||||
role="main"
|
||||
>
|
||||
<Blocks blocks={page.blocks} />
|
||||
<Aside blocks={page.aside} />
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
} catch (err) {
|
||||
|
||||
@@ -32,10 +32,10 @@ export default function RootLayout({
|
||||
id="Cookiebot"
|
||||
src="https://consent.cookiebot.com/uc.js"
|
||||
/>
|
||||
<Script
|
||||
{/* <Script
|
||||
data-cookieconsent="ignore"
|
||||
src="/Static/dist/js/head.js?85c84c9e24ae8da3e7af"
|
||||
/>
|
||||
/> */}
|
||||
<Script
|
||||
data-cookieconsent="ignore"
|
||||
src="/Static/dist/js/inline.js?00133e5a37de35c51a5d"
|
||||
@@ -56,11 +56,11 @@ export default function RootLayout({
|
||||
data-cookieconsent="ignore"
|
||||
src="/Static/dist/js/ng/main.js?1705409330990"
|
||||
/>
|
||||
<Script
|
||||
{/* <Script
|
||||
data-cookieconsent="ignore"
|
||||
src="/Static/dist/js/main-ng.js?336b801d6b38eff10884"
|
||||
strategy="lazyOnload"
|
||||
/>
|
||||
/> */}
|
||||
</head>
|
||||
<body>
|
||||
<LangPopup lang={params.lang} />
|
||||
|
||||
8
app/[lang]/not-found.tsx
Normal file
8
app/[lang]/not-found.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
export default function NotFound() {
|
||||
return (
|
||||
<main>
|
||||
<h2>Not Found</h2>
|
||||
<p>Could not find requested resource</p>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
export default function Home() {
|
||||
return <main>Hello world!</main>;
|
||||
export default async function Home() {
|
||||
return (
|
||||
<main>
|
||||
<h1>Hello world!</h1>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user