Skip to content

Commit cd44b7b

Browse files
committed
Fix
1 parent 6ddc2ab commit cd44b7b

3 files changed

Lines changed: 36 additions & 4 deletions

File tree

apps/codebattle/assets/js/widgets/pages/event/ParticipantDashboard.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function ParticipantDashboard() {
3838
stage.tournamentFinished &&
3939
stage.tournamentId &&
4040
stage.groupTournamentId &&
41+
stage.userStatus !== "completed" &&
4142
!stage.groupTournamentFinished,
4243
);
4344

@@ -136,7 +137,7 @@ function ParticipantDashboard() {
136137
<a
137138
type="button"
138139
className="btn btn-success rounded-pill px-4"
139-
href={`/tournaments/${stage.tournamentId}`}
140+
href={`/tournaments/${stage.tournamentId}?auto_join=1`}
140141
>
141142
{i18n.t(stage.actionButtonText)}
142143
</a>

apps/codebattle/assets/js/widgets/pages/tournament/Tournament.jsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useCallback, useEffect, useMemo } from "react";
1+
import React, { useState, useCallback, useEffect, useMemo, useRef } from "react";
22

33
import cn from "classnames";
44
import has from "lodash/has";
@@ -10,7 +10,7 @@ import { useDispatch, useSelector } from "react-redux";
1010
import CustomEventStylesContext from "../../components/CustomEventStylesContext";
1111
import TournamentStates from "../../config/tournament";
1212
import { connectToChat } from "../../middlewares/Chat";
13-
import { connectToTournament } from "../../middlewares/Tournament";
13+
import { connectToTournament, joinTournament } from "../../middlewares/Tournament";
1414
import { connectToTournament as connectToTournamentAdmin } from "../../middlewares/TournamentAdmin";
1515
import * as selectors from "../../selectors";
1616
import { actions } from "../../slices";
@@ -179,6 +179,37 @@ function Tournament() {
179179
// eslint-disable-next-line react-hooks/exhaustive-deps
180180
}, []);
181181

182+
const autoJoinAttemptedRef = useRef(false);
183+
useEffect(() => {
184+
if (autoJoinAttemptedRef.current) return;
185+
if (!searchParams.has("auto_join")) return;
186+
if (!tournament?.channel?.online) return;
187+
if (!tournament?.id || !currentUserId || isGuest) return;
188+
const joinable = [TournamentStates.waitingParticipants, TournamentStates.active].includes(
189+
tournament.state,
190+
);
191+
if (!joinable) return;
192+
if (tournament.players && tournament.players[currentUserId]) {
193+
autoJoinAttemptedRef.current = true;
194+
return;
195+
}
196+
197+
autoJoinAttemptedRef.current = true;
198+
joinTournament();
199+
200+
const url = new URL(window.location.href);
201+
url.searchParams.delete("auto_join");
202+
window.history.replaceState({}, "", url.toString());
203+
}, [
204+
tournament?.id,
205+
tournament.state,
206+
tournament?.channel?.online,
207+
tournament.players,
208+
currentUserId,
209+
isGuest,
210+
searchParams,
211+
]);
212+
182213
useEffect(() => {
183214
if (!canModerate) {
184215
return undefined;

apps/codebattle/priv/gettext/ru/LC_MESSAGES/default.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,7 @@ msgid "Fullscreen"
17711771
msgstr "Полный экран"
17721772

17731773
msgid "Your next step is the AI-round group tournament. Click the button below to continue."
1774-
msgstr "Теперь переходи к финальной задаче квалификации — её можно решить с AI-ассистентом на платформе SourceCraft. После этого квалификация будет полностью завершена."
1774+
msgstr "Теперь переходи к задаче с AI-ассистентом на платформе SourceCraft."
17751775

17761776
msgid "Go to AI-round group tournament"
17771777
msgstr "Перейти к задаче"

0 commit comments

Comments
 (0)