// Primus IQ — Leaderboard Screen const LEADERBOARD_PAGE_SIZE = 50; // rows rendered per "page" — windowed so a big board stays light const ScreenLeaderboard = ({ currentUser }) => { const [entries, setEntries] = React.useState([]); const [loading, setLoading] = React.useState(false); const [myRank, setMyRank] = React.useState(null); const [myScore, setMyScore] = React.useState(0); const [totalUsers, setTotalUsers] = React.useState(0); const [visible, setVisible] = React.useState(LEADERBOARD_PAGE_SIZE); React.useEffect(() => { setLoading(true); PrimusAPI.getLeaderboard(100) .then(data => { setEntries(data?.entries || []); setMyRank(data?.your_rank ?? null); setMyScore(data?.your_score ?? 0); setTotalUsers(data?.total_users ?? 0); }) .catch(() => { setEntries([]); setMyRank(null); setMyScore(0); setTotalUsers(0); }) .finally(() => setLoading(false)); }, []); // Only show users who have actually uploaded something const board = entries .filter(e => (e.total_uploads || 0) > 0) .map((entry, index) => ({ rank: entry.rank || index + 1, userId: entry.user_id, name: entry.full_name || 'Unknown user', designation: entry.designation || 'Primus Partners', uploads: entry.total_uploads || 0, score: entry.score || 0, isCurrentUser: currentUser && (entry.user_id === currentUser.id || entry.full_name === currentUser.full_name), })); // Windowed rendering — keeps a large board from mounting every row at once. const shown = board.slice(0, visible); const hasMore = board.length > visible; const rankLabel = myRank ? `${myRank}/${totalUsers}` : '—'; return (
Contributions

Leaderboard

Scores come from artifacts added to projects and the firm library.

{loading ? ( ) : board.length === 0 ? ( ) : (
{/* Header */}
Rank Person Uploads Score
{/* Scrollable rows */}
{shown.map((entry, index) => { const initials = entry.name.split(' ').filter(Boolean).map(w => w[0].toUpperCase()).slice(0, 2).join('') || '?'; return (
#{entry.rank}/{totalUsers}
{initials}
{entry.name} {entry.isCurrentUser && You}
{entry.designation}
{entry.uploads}  files
{entry.score}
); })} {hasMore && (
)}
)}
); }; const LeaderboardMetric = ({ label, value }) => (
{label}
{value}
); const LeaderboardEmpty = ({ text }) => (
{text}
); Object.assign(window, { ScreenLeaderboard, LeaderboardMetric, LeaderboardEmpty, });