+ useEffect(() => {
+ window.Echo.channel(`Tournament.${id}`)
+ .listen('ResultReported', e => {
+ if (e.result) {
+ setTournament(tournament => patchResult(tournament, e.result));
+ }
+ })
+ .listen('RoundAdded', e => {
+ if (e.round) {
+ setTournament(tournament => ({
+ ...tournament,
+ 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}`);
+ };
+ }, [id]);
+
+ useEffect(() => {
+ const cb = (e) => {
+ if (e.user) {
+ setTournament(tournament => patchUser(tournament, e.user));
+ }
+ };
+ window.Echo.channel('App.Control')
+ .listen('UserChanged', cb);
+ return () => {
+ window.Echo.channel('App.Control')
+ .stopListening('UserChanged', cb);
+ };
+ }, []);
+