web: centralize prop fetching for live + preview, fix preview banner breakage
This commit is contained in:
@@ -1,42 +1,19 @@
|
||||
import { Metadata, ResolvingMetadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
import { ContactIndexFragment } from "@/gql/graphql";
|
||||
import { getClient } from "@/app/client";
|
||||
import {
|
||||
ContactIndexView,
|
||||
contactQuery,
|
||||
loadContactIndexProps,
|
||||
} from "@/components/contact/ContactIndexView";
|
||||
import { getSeoMetadata } from "@/lib/seo";
|
||||
|
||||
export async function generateMetadata(
|
||||
{ params }: { params: Promise<{}> },
|
||||
_: unknown,
|
||||
parent: ResolvingMetadata
|
||||
): Promise<Metadata | null> {
|
||||
const { data, error } = await getClient().query(contactQuery, {});
|
||||
|
||||
if (error) {
|
||||
throw new Error(error.message);
|
||||
}
|
||||
if (!data?.index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const index = data.index as ContactIndexFragment;
|
||||
const metadata = await getSeoMetadata(index, parent);
|
||||
return metadata;
|
||||
const { index } = await loadContactIndexProps();
|
||||
return getSeoMetadata(index, parent);
|
||||
}
|
||||
|
||||
export default async function Page() {
|
||||
const { data, error } = await getClient().query(contactQuery, {});
|
||||
|
||||
if (error) {
|
||||
throw new Error(error.message);
|
||||
}
|
||||
if (!data?.index) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
const index = data.index as ContactIndexFragment;
|
||||
|
||||
return <ContactIndexView index={index} />;
|
||||
const props = await loadContactIndexProps();
|
||||
return <ContactIndexView {...props} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user