import React, { useState, useEffect } from 'react'; import { Card } from '../ui/card'; import { LeaderboardEntry } from '../../types'; import { ChevronUp, ChevronDown, Minus, Crown, Loader2 } from 'lucide-react'; import { gamificationService } from '../../services/gamificationService'; import { logger } from '@/utils/logger'; export const LeaderboardView: React.FC = () => { const [period, setPeriod] = useState<'weekly' | 'monthly' | 'all'>('weekly'); const [leaderboard, setLeaderboard] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { const loadLeaderboard = async () => { setLoading(true); try { const data = await gamificationService.getLeaderboard(period); setLeaderboard(data); } catch (e) { logger.error('Error loading leaderboard', { error: e instanceof Error ? e.message : String(e), stack: e instanceof Error ? e.stack : undefined, period, }); } finally { setLoading(false); } }; loadLeaderboard(); }, [period]); return (
{/* Header */}

LEADERBOARD

Top producers dominating the network.

{['weekly', 'monthly', 'all'].map((p) => ( ))}
{loading ? (
) : ( <> {/* Top 3 Podium (Visual) */} {leaderboard.length >= 3 && (
{[leaderboard[1], leaderboard[0], leaderboard[2]].map( (entry, i) => (
{i === 1 && ( )}
{entry.rank}
{entry.username}
{entry.xp.toLocaleString()} XP
), )}
)} {/* Table */} {leaderboard.map((entry) => ( ))}
Rank Producer Level XP Trend
#{entry.rank}
{entry.username}
LVL {entry.level} {entry.xp.toLocaleString()} {entry.trend > 0 ? ( {entry.trend} ) : entry.trend < 0 ? ( {' '} {Math.abs(entry.trend)} ) : ( )}
)}
); };