feat: ranking in-progress indicator persists across all admin users
All checks were successful
Build and Push Docker Image / build (push) Successful in 10m1s
All checks were successful
Build and Push Docker Image / build (push) Successful in 10m1s
- Create snapshot with status RUNNING before AI call starts - Update to COMPLETED/FAILED when done - Dashboard derives rankingInProgress from server snapshot status - All admins see the spinner, not just the one who triggered it - Poll snapshots every 3s so progress updates appear quickly Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -274,11 +274,17 @@ export function RankingDashboard({ competitionId: _competitionId, roundId }: Ran
|
||||
// ─── tRPC queries ─────────────────────────────────────────────────────────
|
||||
const { data: snapshots, isLoading: snapshotsLoading } = trpc.ranking.listSnapshots.useQuery(
|
||||
{ roundId },
|
||||
{ refetchInterval: 30_000 },
|
||||
// Poll every 3s so all admins see ranking progress/completion quickly
|
||||
{ refetchInterval: 3_000 },
|
||||
)
|
||||
|
||||
const latestSnapshotId = snapshots?.[0]?.id ?? null
|
||||
const latestSnapshot = snapshots?.[0] ?? null
|
||||
// Derive ranking-in-progress from server state (visible to ALL admins)
|
||||
const rankingInProgress = snapshots?.[0]?.status === 'RUNNING'
|
||||
|
||||
// Find the latest COMPLETED snapshot (skip RUNNING/FAILED)
|
||||
const latestCompleted = snapshots?.find((s) => s.status === 'COMPLETED')
|
||||
const latestSnapshotId = latestCompleted?.id ?? null
|
||||
const latestSnapshot = latestCompleted ?? null
|
||||
|
||||
const { data: snapshot, isLoading: snapshotLoading } = trpc.ranking.getSnapshot.useQuery(
|
||||
{ snapshotId: latestSnapshotId! },
|
||||
@@ -322,20 +328,16 @@ export function RankingDashboard({ competitionId: _competitionId, roundId }: Ran
|
||||
onError: (err) => toast.error(`Failed to save: ${err.message}`),
|
||||
})
|
||||
|
||||
const [rankingInProgress, setRankingInProgress] = useState(false)
|
||||
|
||||
const triggerRankMutation = trpc.ranking.triggerAutoRank.useMutation({
|
||||
onMutate: () => setRankingInProgress(true),
|
||||
onSuccess: () => {
|
||||
toast.success('Ranking complete!')
|
||||
initialized.current = false // allow re-init on next snapshot load
|
||||
void utils.ranking.listSnapshots.invalidate({ roundId })
|
||||
void utils.ranking.getSnapshot.invalidate()
|
||||
setRankingInProgress(false)
|
||||
},
|
||||
onError: (err) => {
|
||||
toast.error(err.message)
|
||||
setRankingInProgress(false)
|
||||
void utils.ranking.listSnapshots.invalidate({ roundId })
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user