web: centralize prop fetching for live + preview, fix preview banner breakage
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { graphql } from "@/gql";
|
||||
import { AssociationFragment, AssociationIndexFragment } from "@/gql/graphql";
|
||||
import { getClient } from "@/app/client";
|
||||
import { AssociationList } from "@/components/associations/AssociationList";
|
||||
import { PageHeader } from "@/components/general/PageHeader";
|
||||
import { PageContent } from "@/components/general/PageContent";
|
||||
@@ -40,7 +41,7 @@ const AssociationFragmentDefinition = graphql(`
|
||||
}
|
||||
`);
|
||||
|
||||
export const allAssociationsQuery = graphql(`
|
||||
const allAssociationsQuery = graphql(`
|
||||
query allAssociations {
|
||||
index: associationIndex {
|
||||
... on AssociationIndex {
|
||||
@@ -58,13 +59,27 @@ export const allAssociationsQuery = graphql(`
|
||||
}
|
||||
`);
|
||||
|
||||
export type AssociationIndexViewProps = {
|
||||
index: AssociationIndexFragment;
|
||||
associations: AssociationFragment[];
|
||||
};
|
||||
|
||||
export async function loadAssociationIndexProps(overrides?: {
|
||||
indexOverride?: AssociationIndexFragment;
|
||||
}): Promise<AssociationIndexViewProps> {
|
||||
const { data, error } = await getClient().query(allAssociationsQuery, {});
|
||||
if (error) throw new Error(error.message);
|
||||
const index =
|
||||
overrides?.indexOverride ?? (data?.index as AssociationIndexFragment | undefined);
|
||||
if (!index) throw new Error("Failed to load /foreninger");
|
||||
const associations = (data?.associations ?? []) as AssociationFragment[];
|
||||
return { index, associations };
|
||||
}
|
||||
|
||||
export function AssociationIndexView({
|
||||
index,
|
||||
associations,
|
||||
}: {
|
||||
index: AssociationIndexFragment;
|
||||
associations: AssociationFragment[];
|
||||
}) {
|
||||
}: AssociationIndexViewProps) {
|
||||
return (
|
||||
<main className="site-main" id="main">
|
||||
<PageHeader heading={index.title} lead={index.lead} />
|
||||
|
||||
Reference in New Issue
Block a user