Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ReDBrother committed Feb 5, 2024
1 parent 58f84f3 commit eeb68d8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -76,6 +74,11 @@ function MatchConfirmationModal({
}, [modalShowing]);

useEffect(() => {
if (nextMatch?.gameId && !modalShowing && redirectImmediatly) {
openNextMatch(nextMatch);
return () => {};
}

if (nextMatch?.gameId && !modalShowing) {
setModalShowing(true);
}
Expand All @@ -84,7 +87,7 @@ function MatchConfirmationModal({
setModalShowing(false);
}

if (nextMatch?.gameId) {
if (nextMatch?.gameId && !redirectImmediatly) {
const timerId = window.setInterval(() => {
setRemainingTime(time => {
if (time === null) {
Expand Down Expand Up @@ -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 (
<Modal show={modalShowing} onHide={handleCancel}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,26 +201,37 @@ function Tournament() {

if (activePresentationMode) {
return (
<div
className="d-flex flex-column justify-content-center align-items-center p-3"
>
{has(tournament.players, currentUserId) || tournament.state !== TournamentStates.waitingParticipants
? (
<span className="h3">
{getTournamentPresentationStatus(tournament.state)}
</span>
) : (
<>
<span className="h3">{tournament.name}</span>
<div className="d-flex">
<JoinButton
isShow
isParticipant={false}
/>
</div>
</>
)}
</div>
<>
<MatchConfirmationModal
players={tournament.players}
matches={tournament.matches}
currentUserId={currentUserId}
modalShowing={matchConfirmationModalShowing}
setModalShowing={setMatchConfirmationModalShowing}
currentRoundPosition={tournament.currentRoundPosition}
redirectImmediatly={activePresentationMode}
/>
<div
className="d-flex flex-column justify-content-center align-items-center p-3"
>
{has(tournament.players, currentUserId) || tournament.state !== TournamentStates.waitingParticipants
? (
<span className="h3">
{getTournamentPresentationStatus(tournament.state)}
</span>
) : (
<>
<span className="h3">{tournament.name}</span>
<div className="d-flex">
<JoinButton
isShow
isParticipant={false}
/>
</div>
</>
)}
</div>
</>
);
}

Expand Down Expand Up @@ -269,6 +280,7 @@ function Tournament() {
currentUserId={currentUserId}
modalShowing={matchConfirmationModalShowing}
setModalShowing={setMatchConfirmationModalShowing}
currentRoundPosition={tournament.currentRoundPosition}
redirectImmediatly={activePresentationMode}
/>
<div className="container-fluid mb-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit eeb68d8

Please sign in to comment.