diff --git a/client/src/screens/LeaderboardScreen.tsx b/client/src/screens/LeaderboardScreen.tsx index a4d0eee..0c87ea8 100644 --- a/client/src/screens/LeaderboardScreen.tsx +++ b/client/src/screens/LeaderboardScreen.tsx @@ -2,6 +2,7 @@ import { useEffect, useState } from 'react'; import { api } from '../api/api'; import type { LeaderboardResponse } from '../api/types'; import { useAuth } from '../auth/AuthContext'; +import { getSocket } from '../realtime/socket'; import { formatMoney } from '../shared/format'; type Metric = 'money' | 'reputation'; @@ -16,6 +17,17 @@ export function LeaderboardScreen() { void api.leaderboard(metric).then(setBoard); }, [metric]); + // Aggiornamento live quando il server ricalcola le classifiche + useEffect(() => { + const socket = getSocket(); + if (!socket) return; + const onUpdate = () => void api.leaderboard(metric).then(setBoard); + socket.on('leaderboard:updated', onUpdate); + return () => { + socket.off('leaderboard:updated', onUpdate); + }; + }, [metric]); + return (
- Prezzo a sinistra: acquisto · a destra: vendita. I prezzi cambiano ogni minuto. + Prezzo a sinistra: acquisto · a destra: vendita. I prezzi cambiano ogni minuto: compra + dove c'è l'affare, vendi dove rende.
{selected && (