web: fetch some content

This commit is contained in:
2024-05-07 04:05:40 +02:00
parent 3fdb4b92a2
commit 5b9c484f14
6 changed files with 394 additions and 12 deletions

View File

@ -0,0 +1,65 @@
import { gql } from "@apollo/client";
import { getClient } from "@/app/client";
export async function generateStaticParams() {
const query = gql(`
{
pages(contentType: "events.EventPage") {
id
slug
}
}
`);
const { data } = await getClient().query({
query: query,
});
return data.pages.map((page: any) => ({
slug: page.slug,
}));
}
export default async function Page({ params }: { params: { slug: string } }) {
const query = gql(`
query ($slug: String!) {
event: page(contentType: "events.EventPage", slug: $slug) {
id
slug
title
... on EventPage {
body {
id
blockType
}
}
}
}
`);
// const response = await getClient()
// .query({
// query: query,
// variables: { slug: params.slug },
// })
// .then()
// .catch((e) => console.error(e.networkError.result.errors));
const { data } = await getClient().query({
query: query,
variables: { slug: params.slug },
});
const { event } = data;
return (
<main className="site-main" id="main">
<section className="page-header textOnly">
<h1>Et enkeltarrangement</h1>
<p>!!</p>
</section>
<section className="page-content">
<div key={event.id}>{event.title}</div>
</section>
</main>
);
}

View File

@ -0,0 +1,39 @@
import { gql } from "@apollo/client";
import { getClient } from "@/app/client";
export default async function Page() {
const query = gql(`
{
pages(contentType: "events.EventPage") {
id
slug
title
... on EventPage {
body {
id
blockType
}
}
}
}
`);
const { data } = await getClient().query({
query: query,
});
return (
<main className="site-main" id="main">
<section className="page-header textOnly">
<h1>Arrangementer</h1>
<p>woo</p>
</section>
{data.pages && (
<section className="page-content">
{data.pages.map((event) => (
<div key={event.id}>{event.title}</div>
))}
</section>
)}
</main>
);
}

11
web/src/app/client.ts Normal file
View File

@ -0,0 +1,11 @@
import { ApolloClient, HttpLink, InMemoryCache } from "@apollo/client";
import { registerApolloClient } from "@apollo/experimental-nextjs-app-support/rsc";
export const { getClient } = registerApolloClient(() => {
return new ApolloClient({
cache: new InMemoryCache(),
link: new HttpLink({
uri: "https://cms.neuf.kult.444.no/api/graphql/",
}),
});
});

View File

@ -15,7 +15,7 @@ export default function RootLayout({
children: React.ReactNode;
}>) {
return (
<html lang="en">
<html lang="no">
<body className={inter.className}>{children}</body>
</html>
);