From 2cdd3b234794f72d35914d5509ba7c161db62ac7 Mon Sep 17 00:00:00 2001 From: Brandon Egger Date: Tue, 22 Aug 2023 16:48:05 -0500 Subject: [PATCH] remove static rendering --- src/pages/resources/[id]/index.tsx | 54 +++--------------------------- 1 file changed, 4 insertions(+), 50 deletions(-) diff --git a/src/pages/resources/[id]/index.tsx b/src/pages/resources/[id]/index.tsx index 76e16ff..9fe28f8 100644 --- a/src/pages/resources/[id]/index.tsx +++ b/src/pages/resources/[id]/index.tsx @@ -1,9 +1,5 @@ -import { type InferGetStaticPropsType, type GetStaticPropsContext } from "next"; import { GlobeAltIcon, DocumentIcon } from "@heroicons/react/24/solid"; import { PencilSquareIcon } from "@heroicons/react/20/solid"; -import { createServerSideHelpers } from "@trpc/react-query/server"; -import { appRouter } from "~/server/api/root"; -import { prisma } from "~/server/db"; import { api } from "~/utils/api"; import { ResourceDescription, ResourceInfo } from "~/components/ResourceTable"; import { type PlatformLink } from "@prisma/client"; @@ -15,47 +11,6 @@ import { AdminBarLayout } from "~/components/admin/ControlBar"; import { AdminActionLink } from "~/components/admin/common"; import { useRouter } from "next/router"; -export const getStaticPaths = async () => { - const resources = await prisma.auditoryResource.findMany({ - select: { - id: true, - }, - }); - - return { - paths: resources.map((resource) => ({ - params: { - id: resource.id, - }, - })), - fallback: "blocking", - }; -}; - -export async function getStaticProps( - context: GetStaticPropsContext<{ id: string }> -) { - const helpers = createServerSideHelpers({ - router: appRouter, - ctx: { - prisma, - session: null, - }, - }); - - const id = context.params?.id as string; - - await helpers.auditoryResource.byId.prefetch({ id }); - - return { - props: { - trpcState: helpers.dehydrate(), - id, - }, - revalidate: 1, - }; -} - export const PlatformLinkButton = ({ platformLink, }: { @@ -123,12 +78,11 @@ const DownloadButtons = ({ return
{buttons}
; }; -const ResourceViewPage = ( - props: InferGetStaticPropsType -) => { - const { id } = props; - const resourceQuery = api.auditoryResource.byId.useQuery({ id }); +const ResourceViewPage = () => { const router = useRouter(); + const id = router.query["id"]?.toString() ?? ""; + + const resourceQuery = api.auditoryResource.byId.useQuery({ id }); const ConditionalView = () => { if (!resourceQuery.data) {