diff --git a/services/app/apps/codebattle/assets/js/widgets/middlewares/Spectator.js b/services/app/apps/codebattle/assets/js/widgets/middlewares/Spectator.js index 07c6cb640..d17d5678d 100644 --- a/services/app/apps/codebattle/assets/js/widgets/middlewares/Spectator.js +++ b/services/app/apps/codebattle/assets/js/widgets/middlewares/Spectator.js @@ -58,13 +58,14 @@ export const connectToSpectator = () => dispatch => { dispatch(actions.clearActiveGameId()); dispatch(actions.clearGameStatus()); + console.log(payload, data); setTimeout(params => { dispatch(actions.setActiveGameId(params)); }, 10, data); }; const refs = [ - currentSpectatorChannel.on('game:create', handleGameCreate), + currentSpectatorChannel.on('game:created', handleGameCreate), ]; const clearSpectatorChannel = () => { diff --git a/services/app/apps/codebattle/assets/js/widgets/pages/tournament/MatchConfirmationModal.jsx b/services/app/apps/codebattle/assets/js/widgets/pages/tournament/MatchConfirmationModal.jsx index cdc11b54f..2bc790cc5 100644 --- a/services/app/apps/codebattle/assets/js/widgets/pages/tournament/MatchConfirmationModal.jsx +++ b/services/app/apps/codebattle/assets/js/widgets/pages/tournament/MatchConfirmationModal.jsx @@ -56,12 +56,10 @@ function MatchConfirmationModal({ const timerProgress = getTimerProgress(remainingTime); const handleConfirmation = useCallback(() => { - if (nextMatch?.gameId && redirectImmediatly) { - openNextMatch(nextMatch); - } else if (nextMatch?.gameId) { + if (nextMatch?.gameId) { setOpenMatch(true); } - }, [nextMatch, redirectImmediatly]); + }, [nextMatch]); const handleCancel = useCallback(() => { setModalShowing(false); @@ -76,6 +74,11 @@ function MatchConfirmationModal({ }, [modalShowing]); useEffect(() => { + if (nextMatch?.gameId && !modalShowing && redirectImmediatly) { + openNextMatch(nextMatch); + return () => {}; + } + if (nextMatch?.gameId && !modalShowing) { setModalShowing(true); } @@ -84,7 +87,7 @@ function MatchConfirmationModal({ setModalShowing(false); } - if (nextMatch?.gameId) { + if (nextMatch?.gameId && !redirectImmediatly) { const timerId = window.setInterval(() => { setRemainingTime(time => { if (time === null) { @@ -124,7 +127,7 @@ function MatchConfirmationModal({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [openMatch]); - const title = 'Next match will be oppened. Show now?'; + const title = 'Next match will be opened. Show now?'; return ( diff --git a/services/app/apps/codebattle/assets/js/widgets/pages/tournament/Tournament.jsx b/services/app/apps/codebattle/assets/js/widgets/pages/tournament/Tournament.jsx index d2ceec700..f24d22b4c 100644 --- a/services/app/apps/codebattle/assets/js/widgets/pages/tournament/Tournament.jsx +++ b/services/app/apps/codebattle/assets/js/widgets/pages/tournament/Tournament.jsx @@ -201,26 +201,37 @@ function Tournament() { if (activePresentationMode) { return ( -
- {has(tournament.players, currentUserId) || tournament.state !== TournamentStates.waitingParticipants - ? ( - - {getTournamentPresentationStatus(tournament.state)} - - ) : ( - <> - {tournament.name} -
- -
- - )} -
+ <> + +
+ {has(tournament.players, currentUserId) || tournament.state !== TournamentStates.waitingParticipants + ? ( + + {getTournamentPresentationStatus(tournament.state)} + + ) : ( + <> + {tournament.name} +
+ +
+ + )} +
+ ); } @@ -269,6 +280,7 @@ function Tournament() { currentUserId={currentUserId} modalShowing={matchConfirmationModalShowing} setModalShowing={setMatchConfirmationModalShowing} + currentRoundPosition={tournament.currentRoundPosition} redirectImmediatly={activePresentationMode} />
diff --git a/services/app/apps/codebattle/lib/codebattle_web/channels/spectator_channel.ex b/services/app/apps/codebattle/lib/codebattle_web/channels/spectator_channel.ex index 80c9e435c..d6f5f82aa 100644 --- a/services/app/apps/codebattle/lib/codebattle_web/channels/spectator_channel.ex +++ b/services/app/apps/codebattle/lib/codebattle_web/channels/spectator_channel.ex @@ -9,6 +9,8 @@ defmodule CodebattleWeb.SpectatorChannel do player_id = String.to_integer(player_id) tournament_id = payload["tournament_id"] + Codebattle.PubSub.subscribe("tournament:#{tournament_id}:player:#{player_id}") + with tournament when not is_nil(tournament) <- Tournament.Context.get(tournament_id), true <- Tournament.Helpers.can_access?(tournament, current_user, payload) do game_id = tournament |> Tournament.Helpers.get_active_game_id(player_id) @@ -34,8 +36,10 @@ defmodule CodebattleWeb.SpectatorChannel do {:noreply, socket} end - def handle_info(%{event: "game:created", payload: payload}, socket) do - push(socket, "game:created", %{active_game_id: payload.game_id}) + def handle_info(%{event: "tournament:match:upserted", payload: payload}, socket) do + if payload.match.state == "playing" do + push(socket, "game:created", %{active_game_id: payload.match.game_id}) + end {:noreply, socket} end