From 5e974aa3da01e7fa8489c69af36b81963096b60d Mon Sep 17 00:00:00 2001 From: Simon Emanuelsson Date: Thu, 1 Feb 2024 16:19:16 +0100 Subject: [PATCH] feat: graphql client with fetches for initial pages --- .env.example | 4 + app/[lang]/current-content-page/page.tsx | 52 +- app/[lang]/layout.tsx | 8 +- app/[lang]/not-found.tsx | 8 + app/[lang]/page.tsx | 8 +- components/Current/Aside.tsx | 9 + components/Current/Blocks.tsx | 34 + components/Current/Blocks/List.tsx | 7 + components/Current/Blocks/Preamble.tsx | 7 + components/Current/Blocks/Puffs.tsx | 7 + components/Current/Blocks/Text.tsx | 32 + components/Current/Hero/hero.module.css | 4 + components/Current/Hero/index.tsx | 55 + env/client.mjs | 36 + env/schema.mjs | 46 + env/server.mjs | 33 + lib/graphql/Fragments/Aside/Contact.graphql | 14 + lib/graphql/Fragments/Aside/Puff.graphql | 14 + lib/graphql/Fragments/Blocks/List.graphql | 49 + lib/graphql/Fragments/Blocks/Preamble.graphql | 21 + lib/graphql/Fragments/Blocks/Puff.graphql | 15 + lib/graphql/Fragments/Blocks/Text.graphql | 22 + lib/graphql/Fragments/Contact.graphql | 17 + lib/graphql/Fragments/Hero.graphql | 17 + lib/graphql/Fragments/PageLinks.graphql | 9 + lib/graphql/Fragments/Puff.graphql | 43 + lib/graphql/Query/CurrentBlockPage.graphql | 32 + lib/request.ts | 52 + next.config.js | 22 +- package-lock.json | 108 +- package.json | 7 +- public/Static/dist/js/head.js | 2940 ++++++++--------- tsconfig.json | 23 +- types/components/current/aside.ts | 5 + types/components/current/blocks.ts | 5 + types/components/current/blocks/text.ts | 3 + types/components/current/hero.ts | 7 + types/graphql.d.ts | 1 + types/image.ts | 8 + types/request.ts | 3 + types/requests/asides/contact.ts | 23 + types/requests/asides/puff.ts | 8 + types/requests/blocks/list.ts | 46 + types/requests/blocks/preamble.ts | 17 + types/requests/blocks/puff.ts | 8 + types/requests/blocks/text.ts | 19 + types/requests/currentBlockPage.ts | 33 + types/requests/hero.ts | 6 + types/requests/puff.ts | 26 + types/requests/utils/all.ts | 4 + types/requests/utils/asset.ts | 8 + types/requests/utils/edges.ts | 8 + types/requests/utils/externalLink.ts | 5 + types/requests/utils/pageLink.ts | 5 + types/requests/utils/typename.ts | 31 + types/rte.ts | 58 + 56 files changed, 2580 insertions(+), 1512 deletions(-) create mode 100644 .env.example create mode 100644 app/[lang]/not-found.tsx create mode 100644 components/Current/Aside.tsx create mode 100644 components/Current/Blocks.tsx create mode 100644 components/Current/Blocks/List.tsx create mode 100644 components/Current/Blocks/Preamble.tsx create mode 100644 components/Current/Blocks/Puffs.tsx create mode 100644 components/Current/Blocks/Text.tsx create mode 100644 components/Current/Hero/hero.module.css create mode 100644 components/Current/Hero/index.tsx create mode 100644 env/client.mjs create mode 100644 env/schema.mjs create mode 100644 env/server.mjs create mode 100644 lib/graphql/Fragments/Aside/Contact.graphql create mode 100644 lib/graphql/Fragments/Aside/Puff.graphql create mode 100644 lib/graphql/Fragments/Blocks/List.graphql create mode 100644 lib/graphql/Fragments/Blocks/Preamble.graphql create mode 100644 lib/graphql/Fragments/Blocks/Puff.graphql create mode 100644 lib/graphql/Fragments/Blocks/Text.graphql create mode 100644 lib/graphql/Fragments/Contact.graphql create mode 100644 lib/graphql/Fragments/Hero.graphql create mode 100644 lib/graphql/Fragments/PageLinks.graphql create mode 100644 lib/graphql/Fragments/Puff.graphql create mode 100644 lib/graphql/Query/CurrentBlockPage.graphql create mode 100644 lib/request.ts create mode 100644 types/components/current/aside.ts create mode 100644 types/components/current/blocks.ts create mode 100644 types/components/current/blocks/text.ts create mode 100644 types/components/current/hero.ts create mode 100644 types/graphql.d.ts create mode 100644 types/image.ts create mode 100644 types/request.ts create mode 100644 types/requests/asides/contact.ts create mode 100644 types/requests/asides/puff.ts create mode 100644 types/requests/blocks/list.ts create mode 100644 types/requests/blocks/preamble.ts create mode 100644 types/requests/blocks/puff.ts create mode 100644 types/requests/blocks/text.ts create mode 100644 types/requests/currentBlockPage.ts create mode 100644 types/requests/hero.ts create mode 100644 types/requests/puff.ts create mode 100644 types/requests/utils/all.ts create mode 100644 types/requests/utils/asset.ts create mode 100644 types/requests/utils/edges.ts create mode 100644 types/requests/utils/externalLink.ts create mode 100644 types/requests/utils/pageLink.ts create mode 100644 types/requests/utils/typename.ts create mode 100644 types/rte.ts diff --git a/.env.example b/.env.example new file mode 100644 index 000000000..3fe666e0d --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +CMS_ACCESS_TOKEN="" +CMS_API_KEY="" +CMS_ENVIRONMENT="development" +CMS_URL="https://eu-graphql.contentstack.com/stacks/${CMS_API_KEY}?environment=${CMS_ENVIRONMENT}" diff --git a/app/[lang]/current-content-page/page.tsx b/app/[lang]/current-content-page/page.tsx index 98eafe533..9d37915e9 100644 --- a/app/[lang]/current-content-page/page.tsx +++ b/app/[lang]/current-content-page/page.tsx @@ -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(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 ( <>
- {json.hero ? ( -
- ) : null} - {json.content ? ( -
- ) : null} + {images?.totalCount ? : null} +
+ +
); } catch (err) { diff --git a/app/[lang]/layout.tsx b/app/[lang]/layout.tsx index 68f4e60b5..e8a85080f 100644 --- a/app/[lang]/layout.tsx +++ b/app/[lang]/layout.tsx @@ -32,10 +32,10 @@ export default function RootLayout({ id="Cookiebot" src="https://consent.cookiebot.com/uc.js" /> -