// Primus IQ — Leaderboard Screen const ScreenLeaderboard = ({ currentUser }) => { const [entries, setEntries] = React.useState([]); const [loading, setLoading] = React.useState(false); const [myRank, setMyRank] = React.useState("—"); const [myScore, setMyScore] = React.useState(0); React.useEffect(() => { setLoading(true); PrimusAPI.getLeaderboard(20) .then(data => { setEntries(data?.entries || []); setMyRank(data?.your_rank ?? "—"); setMyScore(data?.your_score ?? 0); }) .catch(() => { setEntries([]); setMyRank("—"); setMyScore(0); }) .finally(() => { setLoading(false); }); }, []); const board = entries.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), })); const currentEntry = board.find(entry => entry.isCurrentUser); return (
Contributions

Leaderboard

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

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