X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fcomponents%2Fpages%2FTournament.js;h=11dc388c67d60c3832a977a7265a93033b7010ee;hb=7016f4b28fa1324269ae9e2a8aad28dd562927d4;hp=64c890609333608f1701941676849ec8308d28f7;hpb=d748feb96453d74aeffec648d6f5f68d9ef3b520;p=alttp.git diff --git a/resources/js/components/pages/Tournament.js b/resources/js/components/pages/Tournament.js index 64c8906..11dc388 100644 --- a/resources/js/components/pages/Tournament.js +++ b/resources/js/components/pages/Tournament.js @@ -7,7 +7,7 @@ import ErrorMessage from '../common/ErrorMessage'; import Loading from '../common/Loading'; import NotFound from '../pages/NotFound'; import Detail from '../tournament/Detail'; -import { patchResult } from '../../helpers/Tournament'; +import { patchResult, patchRound, sortParticipants } from '../../helpers/Tournament'; const Tournament = () => { const params = useParams(); @@ -24,7 +24,7 @@ const Tournament = () => { .then(response => { setError(null); setLoading(false); - setTournament(response.data); + setTournament(sortParticipants(response.data)); }) .catch(error => { setError(error); @@ -34,9 +34,8 @@ const Tournament = () => { }, [id]); useEffect(() => { - window.Echo.private(`Tournament.${id}`) + window.Echo.channel(`Tournament.${id}`) .listen('ResultReported', e => { - console.log(e); if (e.result) { setTournament(tournament => patchResult(tournament, e.result)); } @@ -45,9 +44,19 @@ const Tournament = () => { if (e.round) { setTournament(tournament => ({ ...tournament, - rounds: [...tournament.rounds, e.round], + rounds: [e.round, ...tournament.rounds], })); } + }) + .listen('RoundChanged', e => { + if (e.round) { + setTournament(tournament => patchRound(tournament, e.round)); + } + }) + .listen('TournamentChanged', e => { + if (e.tournament) { + setTournament(tournament => ({ ...tournament, ...e.tournament })); + } }); return () => { window.Echo.leave(`Tournament.${id}`);