diff --git a/src/pages/resources/[id].tsx b/src/pages/resources/[id].tsx index fee5630..fac9c90 100644 --- a/src/pages/resources/[id].tsx +++ b/src/pages/resources/[id].tsx @@ -4,17 +4,6 @@ import { appRouter } from "~/server/api/root"; import { prisma } from "~/server/db"; import { api } from "~/utils/api"; -const ResourceViewPage = (props: InferGetStaticPropsType) => { - const { id } = props; - const resourceQuery = api.auditoryResource.byId.useQuery({ id }); - - return <> -
- {resourceQuery.data?.name ?? 'loading..'} -
- -}; - export const getStaticPaths = async () => { //const amountPerPage = 10; const resources = (await prisma.auditoryResource.findMany({ @@ -57,4 +46,15 @@ export async function getStaticProps( }; } +const ResourceViewPage = (props: InferGetStaticPropsType) => { + const { id } = props; + const resourceQuery = api.auditoryResource.byId.useQuery({ id }); + + return <> +
+ {resourceQuery.data?.name ?? 'loading..'} +
+ +}; + export default ResourceViewPage \ No newline at end of file diff --git a/src/pages/resources/index.tsx b/src/pages/resources/index.tsx index a1d5744..bd7fde9 100644 --- a/src/pages/resources/index.tsx +++ b/src/pages/resources/index.tsx @@ -1,8 +1,29 @@ +import { createProxySSGHelpers } from "@trpc/react-query/ssg"; import Head from "next/head"; import Link from "next/link"; import ResourceTable from "~/components/ResourceTable"; +import { appRouter } from "~/server/api/root"; +import { prisma } from "~/server/db"; import { api } from "~/utils/api"; +export async function getStaticProps() { + const ssg = createProxySSGHelpers({ + router: appRouter, + ctx: { + prisma, + session: null, + }, + }); + await ssg.auditoryResource.getAll.prefetch(); + + return { + props: { + trpcState: ssg.dehydrate(), + }, + revalidate: 1, + }; +} + const Resources = () => { const query = api.auditoryResource.getAll.useQuery();