+ useEffect(() => {
+ window.Echo.channel(`Tournament.${id}`)
+ .listen('ApplicationAdded', e => {
+ if (e.application) {
+ setTournament(tournament => patchApplication(tournament, e.application));
+ }
+ })
+ .listen('ApplicationChanged', e => {
+ if (e.application) {
+ setTournament(tournament => patchApplication(tournament, e.application));
+ }
+ })
+ .listen('ApplicationRemoved', e => {
+ if (e.application_id) {
+ setTournament(tournament => removeApplication(tournament, e.application_id));
+ }
+ })
+ .listen('ParticipantChanged', e => {
+ console.log(e);
+ if (e.participant) {
+ setTournament(tournament => patchParticipant(tournament, e.participant));
+ }
+ })
+ .listen('ResultChanged', 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);
+ };
+ }, []);
+