"use client"; import { useState, useEffect, useCallback } from 'react'; const MEDALS = ['🥇', '🥈', '🥉']; export default function Leaderboard({ isOpen, onClose }) { const [data, setData] = useState(null); const [loading, setLoading] = useState(false); const fetchLeaderboard = useCallback(() => { setLoading(true); fetch(`/api/leaderboard?t=${Date.now()}`) // cache-bust .then(res => res.json()) .then(d => { setData(d); setLoading(false); }) .catch(() => setLoading(false)); }, []); // Fetch on first open useEffect(() => { if (isOpen && !data) { fetchLeaderboard(); } }, [isOpen, data, fetchLeaderboard]); if (!isOpen) return null; return ( <>
Tallying scores...
No annotations yet. Be the first! 🚀
) : (| # | Annotator | ✅ Verified | ✍️ Added | 📄 Docs | ⭐ Score |
|---|---|---|---|---|---|
| {i < 3 ? MEDALS[i] : i + 1} | {entry.annotator} | {entry.verified} {entry.incorrect > 0 && ( ({entry.correct}✓ {entry.incorrect}✕) )} | {entry.humanAdded} | {entry.docsWorked} | {entry.score} |
Score = Verified + Added