import Loading from '../common/Loading';
import NotFound from '../pages/NotFound';
import Detail from '../tournament/Detail';
-import { patchResult, patchRound, sortParticipants } from '../../helpers/Tournament';
+import { patchResult, patchRound, patchUser, sortParticipants } from '../../helpers/Tournament';
const Tournament = () => {
const params = useParams();
}, [id]);
useEffect(() => {
- window.Echo.private(`Tournament.${id}`)
+ window.Echo.channel(`Tournament.${id}`)
.listen('ResultReported', e => {
if (e.result) {
setTournament(tournament => patchResult(tournament, e.result));
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);
+ };
+ }, []);
+
if (loading) {
return <Loading />;
}