'use client' import { useMemo } from 'react' import { trpc } from '@/lib/trpc/client' import { cn } from '@/lib/utils' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Skeleton } from '@/components/ui/skeleton' export type ScoreDistributionProps = { roundId: string } export function ScoreDistribution({ roundId }: ScoreDistributionProps) { const { data: dist, isLoading } = trpc.analytics.getRoundScoreDistribution.useQuery( { roundId }, { refetchInterval: 15_000 }, ) const maxCount = useMemo(() => dist ? Math.max(...dist.globalDistribution.map((b) => b.count), 1) : 1, [dist]) return ( Score Distribution {dist ? `${dist.totalEvaluations} evaluations \u2014 avg ${dist.averageGlobalScore.toFixed(1)}` : 'Loading...'} {isLoading ? (
{Array.from({ length: 10 }).map((_, i) => )}
) : !dist || dist.totalEvaluations === 0 ? (

No evaluations submitted yet

) : (
{dist.globalDistribution.map((bucket) => { const heightPct = (bucket.count / maxCount) * 100 return (
{bucket.count || ''}
{bucket.score}
) })}
)} ) }