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 { AssociationFragment, AssociationIndexFragment } from "@/gql/graphql";
|
||||
import { getClient } from "@/app/client";
|
||||
import {
|
||||
AssociationIndexView,
|
||||
allAssociationsQuery,
|
||||
loadAssociationIndexProps,
|
||||
} from "@/components/associations/AssociationIndexView";
|
||||
import { getSeoMetadata } from "@/lib/seo";
|
||||
|
||||
export async function generateMetadata(
|
||||
{ params }: { params: Promise<{}> },
|
||||
_: unknown,
|
||||
parent: ResolvingMetadata
|
||||
): Promise<Metadata | null> {
|
||||
const { data, error } = await getClient().query(allAssociationsQuery, {});
|
||||
|
||||
if (error) {
|
||||
throw new Error(error.message);
|
||||
}
|
||||
if (!data?.index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const index = data.index as AssociationIndexFragment;
|
||||
const metadata = await getSeoMetadata(index, parent);
|
||||
return metadata;
|
||||
const { index } = await loadAssociationIndexProps();
|
||||
return getSeoMetadata(index, parent);
|
||||
}
|
||||
|
||||
export default async function Page() {
|
||||
const { data, error } = await getClient().query(allAssociationsQuery, {});
|
||||
|
||||
if (error) {
|
||||
throw new Error(error.message);
|
||||
}
|
||||
if (!data?.associations || !data.index) {
|
||||
throw new Error("Failed to render /foreninger");
|
||||
}
|
||||
|
||||
const associations = data.associations as AssociationFragment[];
|
||||
const index = data.index as AssociationIndexFragment;
|
||||
|
||||
return <AssociationIndexView index={index} associations={associations} />;
|
||||
const props = await loadAssociationIndexProps();
|
||||
return <AssociationIndexView {...props} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user