'use client'; import { AnimatePresence, motion } from 'framer-motion'; import Podium from '@/components/ui/events/podium/Podium'; import { useLeaderboardEvent } from '@/lib/hooks/use-leaderboard'; import { cn } from '@/lib/utils'; import { Timer } from '@/components/ui/Timer'; import { Separator } from '@/components/ui/Separator'; const SCORE_COLORS = ['text-yellow-400', 'text-gray-400', 'text-orange-400']; export default function Leaderboard({ token }: { token: string }) { // TODO CHANGER CECI const CHAPITRE_EVENT = 1; // const subscription: SWRSubscription = (key, { next }) => { // const socket = new WebSocket(key); // socket.addEventListener('message', (event) => { // next(null, JSON.parse(event.data)); // }); // socket.addEventListener('error', (event) => { // console.error(event); // }); // return () => socket.close(); // }; // const { data } = useSWRSubscription( // `wss://${process.env.NEXT_PUBLIC_API_URL?.split('//')[1]}/rleaderboard/${CHAPITRE_EVENT}`, // subscription // ); const { data, isLoading } = useLeaderboardEvent({ token: token, id: CHAPITRE_EVENT }); const scores = [data?.groups] .flat() .sort((a, b) => a!.rank - b!.rank) .map((group, place) => ({ ...group, place })); return (

Tableau des scores

Suivez la progression des élèves en direct

{data && } {data && data.end_date && ( )} {data?.groups.map((group, key) => { const tries = group.players.reduce((a, b) => a + b.tries, 0) || 0; return (
{group.rank}
{group.name} {group.players && group.players.length > 1 ? group.players .map((player) => player.pseudo || 'Anonyme') .sort((a, b) => a.localeCompare(b)) .join(', ') : group.players[0].pseudo}
{/*
Puzzle{puzzles > 1 ? 's' : ''} {puzzles}
*/}
Essai{tries > 1 ? 's' : ''} {tries}
Score {group.players.reduce((a, b) => a + b.score, 0)}
); }) || [...Array(20).keys()].map((i) => ( ))}
); }