]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/pages/Tournament.js
lock tournaments
[alttp.git] / resources / js / components / pages / Tournament.js
index aab442346149865aa01f5bc47185a56f6200eede..11dc388c67d60c3832a977a7265a93033b7010ee 100644 (file)
@@ -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, sortParticipants } from '../../helpers/Tournament';
+import { patchResult, patchRound, sortParticipants } from '../../helpers/Tournament';
 
 const Tournament = () => {
        const params = useParams();
@@ -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}`);