import { useState, useEffect } from 'react' import { useParams, Link } from 'react-router-dom' import { marathonsApi } from '@/api' import type { LeaderboardEntry } from '@/types' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui' import { useAuthStore } from '@/store/auth' import { Trophy, Flame, ArrowLeft, Loader2 } from 'lucide-react' export function LeaderboardPage() { const { id } = useParams<{ id: string }>() const user = useAuthStore((state) => state.user) const [leaderboard, setLeaderboard] = useState([]) const [isLoading, setIsLoading] = useState(true) useEffect(() => { loadLeaderboard() }, [id]) const loadLeaderboard = async () => { if (!id) return try { const data = await marathonsApi.getLeaderboard(parseInt(id)) setLeaderboard(data) } catch (error) { console.error('Failed to load leaderboard:', error) } finally { setIsLoading(false) } } const getRankIcon = (rank: number) => { switch (rank) { case 1: return case 2: return case 3: return default: return {rank} } } if (isLoading) { return (
) } return (

Таблица лидеров

Рейтинг {leaderboard.length === 0 ? (

Пока нет участников

) : (
{leaderboard.map((entry) => (
{getRankIcon(entry.rank)}
{entry.user.nickname} {entry.user.id === user?.id && ( (Вы) )}
{entry.completed_count} выполнено, {entry.dropped_count} пропущено
{entry.current_streak > 0 && (
{entry.current_streak}
)}
{entry.total_points}
очков
))}
)}
) }