diff --git a/src/app/(home)/players/[id]/_components/games-table.tsx b/src/app/(home)/players/[id]/_components/games-table.tsx index e2eb0a2..e22b924 100644 --- a/src/app/(home)/players/[id]/_components/games-table.tsx +++ b/src/app/(home)/players/[id]/_components/games-table.tsx @@ -198,15 +198,16 @@ export function GamesTable({ games }: { games: SelectGames[] }) { >(null) // Use the tRPC useQuery hook to fetch the transcript - const { data: transcriptContent, isLoading } = api.history.getTranscript.useQuery( - { gameNumber: transcriptGameNumber ?? 0 }, - { - // Only fetch when we have a game number and the dialog is open - enabled: transcriptGameNumber !== null && isDialogOpen, - // Don't refetch on window focus - refetchOnWindowFocus: false, - } - ) + const { data: transcriptContent, isLoading } = + api.history.getTranscript.useQuery( + { gameNumber: transcriptGameNumber ?? 0 }, + { + // Only fetch when we have a game number and the dialog is open + enabled: transcriptGameNumber !== null && isDialogOpen, + // Don't refetch on window focus + refetchOnWindowFocus: false, + } + ) // New openTranscript function that sets state instead of opening a new window const openTranscript = (gameNumber: number): void => { @@ -299,18 +300,31 @@ export function GamesTable({ games }: { games: SelectGames[] }) { - - {transcriptGameNumber - ? `Game Transcript #${transcriptGameNumber}` - : 'Game Transcript'} - +
+ + {transcriptGameNumber + ? `Game Transcript #${transcriptGameNumber}` + : 'Game Transcript'} + + {transcriptGameNumber && ( + + )} +
{/* Use iframe to isolate the transcript content and prevent style leakage */}
{isLoading ? (
-
+

Loading transcript...

diff --git a/src/app/transcript/[gameNumber]/page.tsx b/src/app/transcript/[gameNumber]/page.tsx new file mode 100644 index 0000000..b9108a2 --- /dev/null +++ b/src/app/transcript/[gameNumber]/page.tsx @@ -0,0 +1,64 @@ +'use client' + +import { api } from '@/trpc/react' +import { useParams } from 'next/navigation' +import { useEffect, useState } from 'react' + +export default function TranscriptPage() { + const params = useParams() + const gameNumber = Number.parseInt(params.gameNumber as string, 10) + const [error, setError] = useState(null) + + // Use the tRPC useQuery hook to fetch the transcript + const { data: transcriptContent, isLoading } = + api.history.getTranscript.useQuery( + { gameNumber }, + { + // Don't refetch on window focus + refetchOnWindowFocus: false, + onError: (err) => { + setError(`Failed to load transcript: ${err.message}`) + }, + } + ) + + // Use useEffect to set the document title + useEffect(() => { + document.title = `Game Transcript #${gameNumber}` + }, [gameNumber]) + + if (isLoading) { + return ( +
+
+
+

Loading transcript...

+
+
+ ) + } + + if (error) { + return ( +
+

{error}

+
+ ) + } + + if (!transcriptContent) { + return ( +
+

Failed to load transcript. Please try again.

+
+ ) + } + + // Return the transcript content directly as HTML + return ( +
+ ) +} diff --git a/src/app/transcript/layout.tsx b/src/app/transcript/layout.tsx new file mode 100644 index 0000000..dbd318b --- /dev/null +++ b/src/app/transcript/layout.tsx @@ -0,0 +1,11 @@ +export default function TranscriptLayout({ + children, +}: { + children: React.ReactNode +}) { + return ( + + {children} + + ) +}