'use client' import { useEffect } from 'react' import { useParams } from 'next/navigation' import Link from 'next/link' import dynamic from 'next/dynamic' import { trpc } from '@/lib/trpc/client' import { Button } from '@/components/ui/button' import { Skeleton } from '@/components/ui/skeleton' import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert' import { ArrowLeft, Download, ExternalLink, AlertCircle, } from 'lucide-react' const ResourceRenderer = dynamic( () => import('@/components/shared/resource-renderer').then((mod) => mod.ResourceRenderer), { ssr: false, loading: () => (
), } ) export default function JuryResourceDetailPage() { const params = useParams() const resourceId = params.id as string const { data: resource, isLoading, error } = trpc.learningResource.get.useQuery({ id: resourceId }) const logAccess = trpc.learningResource.logAccess.useMutation() const utils = trpc.useUtils() // Log access on mount useEffect(() => { if (resourceId) { logAccess.mutate({ id: resourceId }) } }, [resourceId]) const handleDownload = async () => { try { const { url } = await utils.learningResource.getDownloadUrl.fetch({ id: resourceId }) window.open(url, '_blank') } catch { // silently fail } } if (isLoading) { return (