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"; import Image from "next/image"; import Link from "next/link"; import Footer from "~/components/Footer"; import Header from "~/components/Header"; 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, }; } const PlatformLinkButton = ({ platformLink, }: { platformLink: PlatformLink; }) => { const Inner = () => { switch (platformLink.platform) { case "APP_ANDROID": { return ( {`Download ); } case "APP_IOS": { return ( {`Download ); } case "PDF": { return (
Document
); } case "WEBSITE": { return (
Website
); } } }; return ( ); }; const DownloadButtons = ({ platformLinks, }: { platformLinks: PlatformLink[]; }) => { const buttons = platformLinks.map((paltformLink, index) => { return ; }); return
{buttons}
; }; const ResourceViewPage = ( props: InferGetStaticPropsType ) => { const { id } = props; const resourceQuery = api.auditoryResource.byId.useQuery({ id }); const router = useRouter(); const ConditionalView = () => { if (!resourceQuery.data) { return <>; } return (

Links

Ages {resourceQuery.data.ages.min} {resourceQuery.data.ages.max >= 100 ? "+" : `-${resourceQuery.data.ages.max}`}
); }; return ( <>
} label="Edit Page" href={`${router.asPath}/edit`} /> } >
); }; export default ResourceViewPage;