Skip to content

Commit ce67266

Browse files
committed
Merge branch 'a'
2 parents f838cad + 434295a commit ce67266

File tree

17 files changed

+110
-166
lines changed

17 files changed

+110
-166
lines changed

services/app/apps/codebattle/assets/js/widgets/pages/game/EditorToolbar.jsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import GameActionButtons from './GameActionButtons';
1111
import GameBanPlayerButton from './GameBanPlayerButton';
1212
import GameReportButton from './GameReportButton';
1313
import GameResultIcon from './GameResultIcon';
14-
import TournamentUserGameScore from './TournamentUserGameScore';
1514
import UserGameScore from './UserGameScore';
1615
import VimModeButton from './VimModeButton';
1716

@@ -80,9 +79,6 @@ const EditorToolbar = ({
8079
{mode === GameRoomModes.standard && (
8180
<UserGameScore userId={player.id} />
8281
)}
83-
{mode === GameRoomModes.tournament && (
84-
<TournamentUserGameScore userId={player.id} />
85-
)}
8682
</div>
8783
</div>
8884
</div>

services/app/apps/codebattle/assets/js/widgets/pages/game/TournamentStatisticsModal.jsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ const TournamentStatisticsModal = NiceModal.create(() => {
7474
<div className="d-flex justify-content-between">
7575
<div className="d-flex flex-column align-items-center p-2">
7676
<span className="h4 mb-2">{firstPlayer?.name}</span>
77-
<span className="h4 mb-2">{player.score}</span>
7877
<span className="h4 mb-2">{player.winMatches.length}</span>
7978
<span className="h4 mb-2">
8079
{Math.ceil(player.avgTests)}
@@ -87,14 +86,12 @@ const TournamentStatisticsModal = NiceModal.create(() => {
8786
</div>
8887
<div className="d-flex flex-column align-items-center p-2">
8988
<span className="h4 mb-2">Player</span>
90-
<span className="h4 mb-2">Score</span>
9189
<span className="h4 mb-2">Wins</span>
9290
<span className="h4 mb-2">AVG Tests</span>
9391
<span className="h4 mb-2 text-nowrap">AVG Solving speed</span>
9492
</div>
9593
<div className="d-flex flex-column align-items-center p-2">
9694
<span className="h4 mb-2">{secondPlayer?.name}</span>
97-
<span className="h4 mb-2">{opponent.score}</span>
9895
<span className="h4 mb-2">{opponent.winMatches.length}</span>
9996
<span className="h4 mb-2">
10097
{Math.ceil(opponent.avgTests)}

services/app/apps/codebattle/assets/js/widgets/pages/game/TournamentUserGameScore.jsx

Lines changed: 0 additions & 35 deletions
This file was deleted.

services/app/apps/codebattle/assets/js/widgets/pages/tournament/PlayerStatsPanel.jsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ function PlayerStatsPanel({
115115
<FontAwesomeIcon className="ml-2 text-danger" icon="ban" />
116116
)}
117117
</span>
118-
<span title="Your place in tournament">
119-
<TournamentPlace place={currentPlayer.place + 1} withIcon />
120-
</span>
121118
</div>
122119
</div>
123120
<nav>
@@ -177,7 +174,6 @@ function PlayerStatsPanel({
177174
playerId={currentUserId}
178175
clanId={currentUserClanId}
179176
taskIds={roundTaskIds}
180-
place={currentPlayer.place}
181177
isBanned={currentPlayer.isBanned}
182178
matchList={matchList}
183179
/>
@@ -186,7 +182,6 @@ function PlayerStatsPanel({
186182
type={type}
187183
playerId={currentUserId}
188184
taskIds={currentPlayer.taskIds}
189-
place={currentPlayer.place}
190185
isBanned={currentPlayer.isBanned}
191186
matchList={matchList}
192187
/>
@@ -234,7 +229,6 @@ function PlayerStatsPanel({
234229
type={type}
235230
playerId={currentUserId}
236231
taskIds={currentPlayer.taskIds}
237-
place={currentPlayer.place}
238232
isBanned={currentPlayer.isBanned}
239233
matchList={matchList}
240234
/>

services/app/apps/codebattle/assets/js/widgets/pages/tournament/StatisticsCard.jsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import useMatchesStatistics from '@/utils/useMatchesStatistics';
99
import i18next from '../../../i18n';
1010

1111
import TournamentPlace from './TournamentPlace';
12+
import { userRankingSelector } from '@/selectors';
1213

1314
export function ArenaStatisticsCard({
1415
playerId,
@@ -19,6 +20,7 @@ export function ArenaStatisticsCard({
1920
const hasCustomEventStyles = useContext(CustomEventStylesContext);
2021

2122
const [playerStats] = useMatchesStatistics(playerId, matchList);
23+
const playerRanking = useSelector(userRankingSelector(playerId));
2224
const clanStats = useSelector(state => {
2325
if (Array.isArray(state.tournament.ranking)) {
2426
return state.tournament.ranking.find(({ id }) => id === clanId);
@@ -43,12 +45,12 @@ export function ArenaStatisticsCard({
4345
<div className="d-flex w-100 justify-content-between">
4446
<div className={cardColumnClassName}>
4547
<span className="p-1">{`${i18next.t('Your clan place')}: ${clanStats?.place || '?'}`}</span>
46-
{/* <span className="p-1">{`${i18next.t('Your place')}: ${playerStats.place || '?'}`}</span> */}
48+
<span className="p-1">{`${i18next.t('Your place')}: ${playerRanking.place}`}</span>
4749
<span className="p-1">{`${i18next.t('Task')}: ${playerStats.matchesCount}/${taskIds.length}`}</span>
4850
</div>
4951
<div className={cardColumnClassName}>
5052
<span className="p-1">{`${i18next.t('Your clan score')}: ${clanStats?.score || '?'}`}</span>
51-
<span className="p-1">{`${i18next.t('Your score')}: ${playerStats.score || '?'}`}</span>
53+
<span className="p-1">{`${i18next.t('Your score')}: ${playerRanking?.score}`}</span>
5254
</div>
5355
</div>
5456
<div className="d-flex flex-column w-100">
@@ -83,24 +85,26 @@ export function ArenaStatisticsCard({
8385
}
8486

8587
function StatisticsCard({
86-
playerId, matchList = [], place,
88+
playerId, matchList = []
8789
}) {
8890
const [playerStats] = useMatchesStatistics(playerId, matchList);
91+
const playerRanking = useSelector(userRankingSelector(playerId));
8992

93+
console.log(playerRanking)
9094
const cardClassName = cn(
9195
'd-flex flex-column justify-content-center p-2 w-100',
9296
'align-items-center align-items-md-baseline align-items-lg-baseline align-items-xl-baseline',
9397
);
9498

9599
return (
96100
<div className={cardClassName}>
97-
{place !== undefined && (
101+
{playerRanking?.place !== undefined && (
98102
<h6 title={i18next.t('Your place in tournament')} className="p-1">
99-
<TournamentPlace title={i18next.t('Your place')} place={place + 1} />
103+
<TournamentPlace title={i18next.t('Your place')} place={playerRanking?.place} />
100104
</h6>
101105
)}
102106
<h6 title={i18next.t('Your score')} className="p-1">
103-
{`${i18next.t('Your score')}: ${playerStats.score}`}
107+
{`${i18next.t('Your score')}: ${playerRanking?.score}`}
104108
</h6>
105109
{/* <h6 */}
106110
{/* title="Your task_ids" */}

services/app/apps/codebattle/assets/js/widgets/pages/tournament/TournamentPlace.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
tournamentHideResultsSelector,
1414
} from '@/selectors';
1515

16-
function TourrnamentPlace({
16+
function TournamentPlace({
1717
place,
1818
title = '',
1919
withIcon = false,
@@ -44,4 +44,4 @@ function TourrnamentPlace({
4444
);
4545
}
4646

47-
export default memo(TourrnamentPlace);
47+
export default memo(TournamentPlace);

services/app/apps/codebattle/assets/js/widgets/pages/tournament/UsersMatchList.jsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ function UsersMatchList({
6363
{'Wins: '}
6464
{player.winMatches.length}
6565
</span>
66-
<span className="ml-1 pl-1 border-left border-dark">
67-
{'Round Score: '}
68-
{Math.ceil(player.score)}
69-
</span>
7066
<span className="ml-1 pl-1 border-left border-dark">
7167
{'AVG Tests: '}
7268
{Math.ceil(player.avgTests)}
@@ -135,13 +131,6 @@ function UsersMatchList({
135131
<div
136132
className="d-flex align-items-center justify-content-center w-100 p-0 p-sm-1"
137133
>
138-
<span
139-
title="Match score"
140-
className="text-nowrap mx-2"
141-
>
142-
<FontAwesomeIcon className="text-secondary mr-2" icon="trophy" />
143-
{matchResult.score}
144-
</span>
145134
<span
146135
title="Match success tests percent"
147136
className="text-nowrap mx-2"

services/app/apps/codebattle/assets/js/widgets/selectors/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ export const editorsPanelOptionsSelector = (viewMode, roomMachineState) => state
426426
throw new Error('Invalid view mode for battle room');
427427
};
428428

429+
export const userRankingSelector = userId => state => (state.tournament.ranking?.entries || []).find(({ id }) => id === userId);
429430
export const tournamentIdSelector = state => state.tournament.id;
430431

431432
export const tournamentSelector = state => state.tournament;

services/app/apps/codebattle/assets/js/widgets/utils/useMatchesStatistics.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,21 @@ const emptyStats = {
77
matchesCount: 0,
88
winMatches: [],
99
lostMatches: [],
10-
score: 0,
1110
avgTests: 0,
1211
avgDuration: 0,
1312
};
1413

1514
/**
1615
* return tournament matches statistics for player
1716
*
18-
* @typedef {{result: string, score: number, resultPercent: number, durationSec: number}} PlayerResult
17+
* @typedef {{result: string, resultPercent: number, durationSec: number}} PlayerResult
1918
* @typedef {Object.<number, PlayerResult>} PlayerResults
2019
* @typedef {{playerIds: array, winnerId: number, playerResults: [PlayerResults]}} Match
2120
* @typedef {{
2221
* playerId: {?number},
2322
* matchesCount: number,
2423
* winMatches: Match[],
2524
* lostMatches: Match[],
26-
* score: number,
2725
* avgTests: number,
2826
* avgDuration: number,
2927
* }} PlayerStatistics
@@ -62,15 +60,6 @@ function useMatchesStatistics(playerId, matches) {
6260
&& match.playerIds.some(id => id === match.winnerId),
6361
);
6462

65-
const playerScore = sum(
66-
finishedMatches.map(match => match.playerResults[playerId]?.score || 0),
67-
);
68-
const opponentScore = sum(
69-
finishedMatches.map(
70-
match => match.playerResults[opponentId]?.score || 0,
71-
),
72-
);
73-
7463
const playerAvgTests = matchesCount !== 0
7564
? sum(
7665
finishedMatches.map(
@@ -106,7 +95,6 @@ function useMatchesStatistics(playerId, matches) {
10695
matchesCount: matches.length,
10796
winMatches: playerWinMatches,
10897
lostMatches: playerLostMatches,
109-
score: playerScore,
11098
avgTests: playerAvgTests,
11199
avgDuration: playerAvgDuration,
112100
};
@@ -115,7 +103,6 @@ function useMatchesStatistics(playerId, matches) {
115103
matchesCount: matches.length,
116104
winMatches: opponentWinMatches,
117105
lostMatches: opponentLostMatches,
118-
score: opponentScore,
119106
avgTests: opponentAvgTests,
120107
avgDuration: opponentAvgDuration,
121108
};

services/app/apps/codebattle/lib/codebattle/game/context.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ defmodule Codebattle.Game.Context do
214214
end
215215
end
216216

217+
@spec toggle_ban_player(game_id(), %{player_id: pos_integer()}) :: {:ok, Game.t()} | {:error, atom}
218+
def toggle_ban_player(game_id, %{player_id: player_id}) do
219+
case get_game!(game_id) do
220+
%{is_live: true} = game -> Engine.toggle_ban_player(game, player_id)
221+
_ -> {:error, :game_is_dead}
222+
end
223+
end
224+
217225
@spec unlock_game(game_id, String.t()) :: :ok | {:error, term()}
218226
def unlock_game(game_id, pass_code) do
219227
case get_game!(game_id) do

0 commit comments

Comments
 (0)