Skip to content

Commit 4df7e60

Browse files
committed
Add leaderboard to tournaments
1 parent 48b0c9f commit 4df7e60

File tree

15 files changed

+501
-583
lines changed

15 files changed

+501
-583
lines changed

services/app/apps/codebattle/assets/js/widgets/middlewares/Tournament.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import axios from 'axios';
22
import Gon from 'gon';
33
import { camelizeKeys } from 'humps';
44
import compact from 'lodash/compact';
5+
import groupBy from 'lodash/groupBy';
6+
7+
import { PanelModeCodes } from '@/pages/tournament/ControlPanel';
58

69
import TournamentTypes from '../config/tournamentTypes';
710
import { actions } from '../slices';
@@ -212,6 +215,32 @@ export const uploadPlayers = playerIds => (dispatch, getState) => {
212215
}
213216
};
214217

218+
export const getTask = (taskId, onSuccess) => () => {
219+
channel.push('tournament:get_task', { taskId }).receive('ok', payload => {
220+
const data = camelizeKeys(payload);
221+
222+
onSuccess(data);
223+
});
224+
};
225+
226+
export const getResults = (type, params, onSuccess) => () => {
227+
channel
228+
.push('tournament:get_results', { params: { type, ...params } })
229+
.receive('ok', payload => {
230+
const data = camelizeKeys(payload);
231+
console.log(data);
232+
233+
if (type === PanelModeCodes.topUserByClansMode) {
234+
const result = Object.values(
235+
groupBy(data.results, item => item.clanRank),
236+
);
237+
onSuccess(result);
238+
} else {
239+
onSuccess(data.results);
240+
}
241+
});
242+
};
243+
215244
export const requestMatchesByPlayerId = userId => dispatch => {
216245
channel
217246
.push('tournament:matches:request', { playerId: userId })
@@ -227,12 +256,10 @@ export const uploadPlayersMatches = playerId => dispatch => {
227256

228257
export const joinTournament = teamId => {
229258
const params = teamId !== undefined ? { teamId } : {};
230-
channel
231-
.push('tournament:join', params);
259+
channel.push('tournament:join', params);
232260
};
233261

234262
export const leaveTournament = teamId => {
235263
const params = teamId !== undefined ? { teamId } : {};
236-
channel
237-
.push('tournament:leave', params);
264+
channel.push('tournament:leave', params);
238265
};

services/app/apps/codebattle/assets/js/widgets/middlewares/TournamentAdmin.js

Lines changed: 12 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import axios from 'axios';
22
import Gon from 'gon';
33
import { camelizeKeys } from 'humps';
44
import compact from 'lodash/compact';
5-
import groupBy from 'lodash/groupBy';
6-
7-
import { PanelModeCodes } from '@/pages/tournament/ControlPanel';
85

96
import { actions } from '../slices';
107

@@ -230,56 +227,45 @@ export const uploadPlayersMatches = playerId => (dispatch, getState) => {
230227
};
231228

232229
export const createCustomRound = params => {
233-
channel
234-
.push('tournament:start_round', params);
230+
channel.push('tournament:start_round', params);
235231
};
236232

237233
export const startTournament = () => {
238-
channel
239-
.push('tournament:start', {});
234+
channel.push('tournament:start', {});
240235
};
241236

242237
export const cancelTournament = () => dispatch => {
243-
channel
244-
.push('tournament:cancel', {})
245-
.receive('ok', response => {
246-
dispatch(actions.updateTournamentData(response.tournament));
247-
});
238+
channel.push('tournament:cancel', {}).receive('ok', response => {
239+
dispatch(actions.updateTournamentData(response.tournament));
240+
});
248241
};
249242

250243
export const restartTournament = () => {
251-
channel
252-
.push('tournament:restart', {});
244+
channel.push('tournament:restart', {});
253245
};
254246

255247
export const startRoundTournament = () => {
256-
channel
257-
.push('tournament:start_round', {});
248+
channel.push('tournament:start_round', {});
258249
};
259250

260251
export const finishRoundTournament = () => {
261-
channel
262-
.push('tournament:finish_round', {});
252+
channel.push('tournament:finish_round', {});
263253
};
264254

265255
export const toggleVisibleGameResult = gameId => {
266-
channel
267-
.push('tournament:toggle_match_visible', { gameId });
256+
channel.push('tournament:toggle_match_visible', { gameId });
268257
};
269258

270259
export const openUpTournament = () => {
271-
channel
272-
.push('tournament:open_up', {});
260+
channel.push('tournament:open_up', {});
273261
};
274262

275263
export const showTournamentResults = () => {
276-
channel
277-
.push('tournament:toggle_show_results', {});
264+
channel.push('tournament:toggle_show_results', {});
278265
};
279266

280267
export const sendMatchGameOver = matchId => {
281-
channel
282-
.push('tournament:match:game_over', { matchId });
268+
channel.push('tournament:match:game_over', { matchId });
283269
};
284270

285271
export const toggleBanUser = (userId, isBanned) => dispatch => {
@@ -300,31 +286,6 @@ export const sendNewReportState = (reportId, state) => dispatch => {
300286
.receive('error', error => console.error(error));
301287
};
302288

303-
export const getResults = (type, params, onSuccess) => () => {
304-
channel
305-
.push('tournament:get_results', { params: { type, ...params } })
306-
.receive('ok', payload => {
307-
const data = camelizeKeys(payload);
308-
309-
if (type === PanelModeCodes.topUserByClansMode) {
310-
const result = Object.values(
311-
groupBy(data.results, item => item.clanRank),
312-
);
313-
onSuccess(result);
314-
} else {
315-
onSuccess(data.results);
316-
}
317-
});
318-
};
319-
320-
export const getTask = (taskId, onSuccess) => () => {
321-
channel.push('tournament:get_task', { taskId }).receive('ok', payload => {
322-
const data = camelizeKeys(payload);
323-
324-
onSuccess(data);
325-
});
326-
};
327-
328289
export const pushActiveMatchToStream = gameId => dispatch => {
329290
// Update the Redux state immediately for instant UI feedback
330291
dispatch(actions.setAdminActiveGameId(gameId));

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import React, {
2-
memo,
3-
useState,
4-
useCallback,
5-
useRef,
2+
memo, useState, useCallback, useRef,
63
} from 'react';
74

85
import {
@@ -15,7 +12,7 @@ import {
1512
import { Bubble } from 'react-chartjs-2';
1613
import { useDispatch } from 'react-redux';
1714

18-
import { getResults } from '../../middlewares/TournamentAdmin';
15+
import { getResults } from '../../middlewares/Tournament';
1916

2017
import useTournamentPanel from './useTournamentPanel';
2118

@@ -73,7 +70,10 @@ function ClansChartPanel({ type, state }) {
7370
};
7471

7572
return (
76-
<div ref={chartRef} className="my-2 px-1 mt-lg-0 rounded-lg position-relative cb-overflow-x-auto cb-overflow-y-auto">
73+
<div
74+
ref={chartRef}
75+
className="my-2 px-1 mt-lg-0 rounded-lg position-relative cb-overflow-x-auto cb-overflow-y-auto"
76+
>
7777
<Bubble data={config.data} options={config.options} />
7878
</div>
7979
);

0 commit comments

Comments
 (0)