web: centralize prop fetching for live + preview, fix preview banner breakage
This commit is contained in:
+190
-125
@@ -1,5 +1,61 @@
|
||||
import { cookies } from "next/headers";
|
||||
import { getClient } from "@/app/client";
|
||||
import { PreviewBanner } from "@/components/general/PreviewBanner";
|
||||
import {
|
||||
AssociationIndexView,
|
||||
loadAssociationIndexProps,
|
||||
} from "@/components/associations/AssociationIndexView";
|
||||
import {
|
||||
AssociationPageView,
|
||||
loadAssociationPageProps,
|
||||
} from "@/components/associations/AssociationPageView";
|
||||
import {
|
||||
ContactIndexView,
|
||||
loadContactIndexProps,
|
||||
} from "@/components/contact/ContactIndexView";
|
||||
import {
|
||||
EventIndexView,
|
||||
loadEventIndexProps,
|
||||
} from "@/components/events/EventIndexView";
|
||||
import {
|
||||
EventPageView,
|
||||
loadEventPageProps,
|
||||
} from "@/components/events/EventPageView";
|
||||
import {
|
||||
GenericPageView,
|
||||
loadGenericPageProps,
|
||||
} from "@/components/general/GenericPageView";
|
||||
import {
|
||||
HomePageView,
|
||||
loadHomePageProps,
|
||||
} from "@/components/home/HomePageView";
|
||||
import {
|
||||
NewsIndexView,
|
||||
loadNewsIndexProps,
|
||||
} from "@/components/news/NewsIndexView";
|
||||
import {
|
||||
NewsPageView,
|
||||
loadNewsPageProps,
|
||||
} from "@/components/news/NewsPageView";
|
||||
import {
|
||||
SponsorsPageView,
|
||||
loadSponsorsPageProps,
|
||||
} from "@/components/sponsor/SponsorsPageView";
|
||||
import {
|
||||
StudioPageView,
|
||||
loadStudioPageProps,
|
||||
} from "@/components/studio/StudioPageView";
|
||||
import {
|
||||
VenueIndexView,
|
||||
loadVenueIndexProps,
|
||||
} from "@/components/venues/VenueIndexView";
|
||||
import {
|
||||
VenuePageView,
|
||||
loadVenuePageProps,
|
||||
} from "@/components/venues/VenuePageView";
|
||||
import {
|
||||
VenueRentalIndexView,
|
||||
loadVenueRentalIndexProps,
|
||||
} from "@/components/venues/VenueRentalIndexView";
|
||||
import { graphql } from "@/gql";
|
||||
import {
|
||||
AssociationFragment,
|
||||
@@ -16,36 +72,7 @@ import {
|
||||
VenueIndexFragment,
|
||||
VenueRentalIndexFragment,
|
||||
} from "@/gql/graphql";
|
||||
import {
|
||||
AssociationIndexView,
|
||||
allAssociationsQuery,
|
||||
} from "@/components/associations/AssociationIndexView";
|
||||
import { AssociationPageView } from "@/components/associations/AssociationPageView";
|
||||
import { ContactIndexView } from "@/components/contact/ContactIndexView";
|
||||
import { EventIndexView } from "@/components/events/EventIndexView";
|
||||
import { EventPageView } from "@/components/events/EventPageView";
|
||||
import { GenericPageView } from "@/components/general/GenericPageView";
|
||||
import { HomePageView, homeQuery } from "@/components/home/HomePageView";
|
||||
import { NewsIndexView } from "@/components/news/NewsIndexView";
|
||||
import { NewsPageView } from "@/components/news/NewsPageView";
|
||||
import { SponsorsPageView } from "@/components/sponsor/SponsorsPageView";
|
||||
import { StudioPageView } from "@/components/studio/StudioPageView";
|
||||
import {
|
||||
VenueIndexView,
|
||||
venueIndexQuery,
|
||||
} from "@/components/venues/VenueIndexView";
|
||||
import { VenuePageView } from "@/components/venues/VenuePageView";
|
||||
import {
|
||||
VenueRentalIndexView,
|
||||
venueRentalIndexQuery,
|
||||
} from "@/components/venues/VenueRentalIndexView";
|
||||
import {
|
||||
EventCategory,
|
||||
EventOrganizer,
|
||||
eventsOverviewQuery,
|
||||
} from "@/lib/event";
|
||||
import { newsQuery } from "@/lib/news";
|
||||
|
||||
import { cookies } from "next/headers";
|
||||
export const dynamic = "force-dynamic";
|
||||
export const revalidate = 0;
|
||||
|
||||
@@ -53,19 +80,45 @@ const previewPageQuery = graphql(`
|
||||
query previewPage($token: String!) {
|
||||
page: page(token: $token) {
|
||||
__typename
|
||||
... on GenericPage { ...Generic }
|
||||
... on StudioPage { ...Studio }
|
||||
... on SponsorsPage { ...SponsorsPage }
|
||||
... on HomePage { ...Home }
|
||||
... on EventPage { ...Event }
|
||||
... on NewsPage { ...News }
|
||||
... on AssociationPage { ...Association }
|
||||
... on VenuePage { ...Venue }
|
||||
... on NewsIndex { ...NewsIndex }
|
||||
... on AssociationIndex { ...AssociationIndex }
|
||||
... on VenueIndex { ...VenueIndex }
|
||||
... on VenueRentalIndex { ...VenueRentalIndex }
|
||||
... on ContactIndex { ...ContactIndex }
|
||||
... on GenericPage {
|
||||
...Generic
|
||||
}
|
||||
... on StudioPage {
|
||||
...Studio
|
||||
}
|
||||
... on SponsorsPage {
|
||||
...SponsorsPage
|
||||
}
|
||||
... on HomePage {
|
||||
...Home
|
||||
}
|
||||
... on EventPage {
|
||||
...Event
|
||||
}
|
||||
... on NewsPage {
|
||||
...News
|
||||
}
|
||||
... on AssociationPage {
|
||||
...Association
|
||||
}
|
||||
... on VenuePage {
|
||||
...Venue
|
||||
}
|
||||
... on NewsIndex {
|
||||
...NewsIndex
|
||||
}
|
||||
... on AssociationIndex {
|
||||
...AssociationIndex
|
||||
}
|
||||
... on VenueIndex {
|
||||
...VenueIndex
|
||||
}
|
||||
... on VenueRentalIndex {
|
||||
...VenueRentalIndex
|
||||
}
|
||||
... on ContactIndex {
|
||||
...ContactIndex
|
||||
}
|
||||
}
|
||||
}
|
||||
`);
|
||||
@@ -105,87 +158,99 @@ export default async function PreviewRender() {
|
||||
}
|
||||
|
||||
const page = data.page;
|
||||
switch (page.__typename) {
|
||||
case "GenericPage":
|
||||
return <GenericPageView page={page as GenericFragment} />;
|
||||
case "StudioPage":
|
||||
return <StudioPageView page={page as StudioFragment} />;
|
||||
case "SponsorsPage":
|
||||
return <SponsorsPageView page={page as SponsorsPageFragment} />;
|
||||
case "EventPage":
|
||||
return <EventPageView event={page as EventFragment} />;
|
||||
case "NewsPage":
|
||||
return <NewsPageView news={page as NewsFragment} />;
|
||||
case "AssociationPage":
|
||||
return <AssociationPageView association={page as AssociationFragment} />;
|
||||
case "VenuePage":
|
||||
return <VenuePageView venue={page as VenueFragment} />;
|
||||
|
||||
case "HomePage": {
|
||||
const { data: aux } = await getClient().query(homeQuery, {});
|
||||
const events = (aux?.events?.futureEvents ?? []) as EventFragment[];
|
||||
const news = (aux?.news ?? []) as NewsFragment[];
|
||||
return (
|
||||
<HomePageView home={page as HomeFragment} events={events} news={news} />
|
||||
);
|
||||
const view = await (async () => {
|
||||
switch (page.__typename) {
|
||||
case "GenericPage": {
|
||||
const props = await loadGenericPageProps({
|
||||
pageOverride: page as GenericFragment,
|
||||
});
|
||||
return <GenericPageView {...props!} />;
|
||||
}
|
||||
case "StudioPage": {
|
||||
const props = await loadStudioPageProps({
|
||||
pageOverride: page as StudioFragment,
|
||||
});
|
||||
return <StudioPageView {...props} />;
|
||||
}
|
||||
case "SponsorsPage": {
|
||||
const props = await loadSponsorsPageProps({
|
||||
pageOverride: page as SponsorsPageFragment,
|
||||
});
|
||||
return <SponsorsPageView {...props} />;
|
||||
}
|
||||
case "EventPage": {
|
||||
const props = await loadEventPageProps({
|
||||
eventOverride: page as EventFragment,
|
||||
});
|
||||
return <EventPageView {...props!} />;
|
||||
}
|
||||
case "NewsPage": {
|
||||
const props = await loadNewsPageProps({
|
||||
newsOverride: page as NewsFragment,
|
||||
});
|
||||
return <NewsPageView {...props!} />;
|
||||
}
|
||||
case "AssociationPage": {
|
||||
const props = await loadAssociationPageProps({
|
||||
associationOverride: page as AssociationFragment,
|
||||
});
|
||||
return <AssociationPageView {...props!} />;
|
||||
}
|
||||
case "VenuePage": {
|
||||
const props = await loadVenuePageProps({
|
||||
venueOverride: page as VenueFragment,
|
||||
});
|
||||
return <VenuePageView {...props!} />;
|
||||
}
|
||||
case "HomePage": {
|
||||
const props = await loadHomePageProps({
|
||||
homeOverride: page as HomeFragment,
|
||||
});
|
||||
return <HomePageView {...props} />;
|
||||
}
|
||||
case "EventIndex": {
|
||||
const props = await loadEventIndexProps();
|
||||
return <EventIndexView {...props} />;
|
||||
}
|
||||
case "NewsIndex": {
|
||||
const props = await loadNewsIndexProps({
|
||||
indexOverride: page as NewsIndexFragment,
|
||||
});
|
||||
return <NewsIndexView {...props} />;
|
||||
}
|
||||
case "AssociationIndex": {
|
||||
const props = await loadAssociationIndexProps({
|
||||
indexOverride: page as AssociationIndexFragment,
|
||||
});
|
||||
return <AssociationIndexView {...props} />;
|
||||
}
|
||||
case "VenueIndex": {
|
||||
const props = await loadVenueIndexProps({
|
||||
indexOverride: page as VenueIndexFragment,
|
||||
});
|
||||
return <VenueIndexView {...props} />;
|
||||
}
|
||||
case "VenueRentalIndex": {
|
||||
const props = await loadVenueRentalIndexProps({
|
||||
indexOverride: page as VenueRentalIndexFragment,
|
||||
});
|
||||
return <VenueRentalIndexView {...props} />;
|
||||
}
|
||||
case "ContactIndex": {
|
||||
const props = await loadContactIndexProps({
|
||||
indexOverride: page as ContactIndexFragment,
|
||||
});
|
||||
return <ContactIndexView {...props} />;
|
||||
}
|
||||
default:
|
||||
return <UnsupportedType typename={page.__typename ?? "unknown"} />;
|
||||
}
|
||||
})();
|
||||
|
||||
case "EventIndex": {
|
||||
const { data: aux } = await getClient().query(eventsOverviewQuery, {});
|
||||
const events = (aux?.events?.futureEvents ?? []) as EventFragment[];
|
||||
const eventCategories = (aux?.eventCategories ?? []) as EventCategory[];
|
||||
const eventOrganizers = (aux?.eventOrganizers ?? []) as EventOrganizer[];
|
||||
const venues = (aux?.venues ?? []) as VenueFragment[];
|
||||
return (
|
||||
<EventIndexView
|
||||
events={events}
|
||||
eventCategories={eventCategories}
|
||||
eventOrganizers={eventOrganizers}
|
||||
venues={venues}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
case "NewsIndex": {
|
||||
const { data: aux } = await getClient().query(newsQuery, {});
|
||||
const news = (aux?.news ?? []) as NewsFragment[];
|
||||
return <NewsIndexView index={page as NewsIndexFragment} news={news} />;
|
||||
}
|
||||
|
||||
case "AssociationIndex": {
|
||||
const { data: aux } = await getClient().query(allAssociationsQuery, {});
|
||||
const associations = (aux?.associations ?? []) as AssociationFragment[];
|
||||
return (
|
||||
<AssociationIndexView
|
||||
index={page as AssociationIndexFragment}
|
||||
associations={associations}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
case "VenueIndex": {
|
||||
const { data: aux } = await getClient().query(venueIndexQuery, {});
|
||||
const venues = (aux?.venues ?? []) as VenueFragment[];
|
||||
return (
|
||||
<VenueIndexView index={page as VenueIndexFragment} venues={venues} />
|
||||
);
|
||||
}
|
||||
|
||||
case "VenueRentalIndex": {
|
||||
const { data: aux } = await getClient().query(venueRentalIndexQuery, {});
|
||||
const venues = (aux?.venues ?? []) as VenueFragment[];
|
||||
return (
|
||||
<VenueRentalIndexView
|
||||
index={page as VenueRentalIndexFragment}
|
||||
venues={venues}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
case "ContactIndex":
|
||||
return <ContactIndexView index={page as ContactIndexFragment} />;
|
||||
|
||||
default:
|
||||
return <UnsupportedType typename={page.__typename ?? "unknown"} />;
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<PreviewBanner />
|
||||
{view}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user