Skip to content

Commit 48b0c9f

Browse files
committed
wip
1 parent f9ac13a commit 48b0c9f

File tree

3 files changed

+461
-130
lines changed

3 files changed

+461
-130
lines changed

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

Lines changed: 111 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
import React, {
2-
memo, useCallback, useContext,
3-
} from 'react';
4-
5-
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
6-
import cn from 'classnames';
7-
import i18next from 'i18next';
8-
import { useSelector } from 'react-redux';
9-
import AsyncSelect from 'react-select/async';
10-
11-
import CustomEventStylesContext from '../../components/CustomEventStylesContext';
12-
import UserLabel from '../../components/UserLabel';
13-
import {
14-
tournamentPlayersSelector,
15-
} from '../../selectors';
1+
import React, { memo, useCallback, useContext } from "react";
2+
3+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
4+
import cn from "classnames";
5+
import i18next from "i18next";
6+
import { useSelector } from "react-redux";
7+
import AsyncSelect from "react-select/async";
8+
9+
import CustomEventStylesContext from "../../components/CustomEventStylesContext";
10+
import UserLabel from "../../components/UserLabel";
11+
import { tournamentPlayersSelector } from "../../selectors";
12+
import Leaderboard from "../lobby/Leaderboard";
1613

1714
// %{"type" => "top_users_by_clan_ranking"} ->
1815
// %{"type" => "tasks_ranking"} ->
@@ -21,88 +18,97 @@ import {
2118
// %{"type" => "top_user_by_task_ranking", "task_id" => task_id} ->
2219
//
2320
export const PanelModeCodes = {
24-
ratingMode: 'ratingMode',
25-
reportsMode: 'reportsMode',
26-
playerMode: 'playerMode',
27-
topUserByClansMode: 'top_users_by_clan_ranking',
28-
taskRatingMode: 'tasks_ranking',
29-
clansBubbleDistributionMode: 'clans_bubble_distribution',
30-
taskRatingAdvanced: 'task_rating_advanced',
31-
taskDurationDistributionMode: 'task_duration_distribution',
32-
topUserByTasksMode: 'top_user_by_task_ranking',
21+
ratingMode: "ratingMode",
22+
reportsMode: "reportsMode",
23+
leaderboardMode: "leaderboardMode",
24+
playerMode: "playerMode",
25+
topUserByClansMode: "top_users_by_clan_ranking",
26+
taskRatingMode: "tasks_ranking",
27+
clansBubbleDistributionMode: "clans_bubble_distribution",
28+
taskRatingAdvanced: "task_rating_advanced",
29+
taskDurationDistributionMode: "task_duration_distribution",
30+
topUserByTasksMode: "top_user_by_task_ranking",
3331
};
3432

3533
export const mapPanelModeToTitle = {
36-
[PanelModeCodes.ratingMode]: i18next.t('Rating Panel'),
37-
[PanelModeCodes.reportsMode]: i18next.t('Reports Panel'),
38-
[PanelModeCodes.playerMode]: i18next.t('Player Panel'),
39-
[PanelModeCodes.topUserByClansMode]: i18next.t('Top users by clan ranking'),
40-
[PanelModeCodes.taskRatingMode]: i18next.t('Tasks ranking'),
41-
[PanelModeCodes.clansBubbleDistributionMode]: i18next.t('Clans bubble distribution'),
42-
[PanelModeCodes.taskRatingAdvanced]: i18next.t('Duration distribution and top users by task'),
43-
[PanelModeCodes.taskDurationDistributionMode]: i18next.t('task duration distribution'),
44-
[PanelModeCodes.topUserByTasksMode]: i18next.t('Top user by task ranking'),
34+
[PanelModeCodes.ratingMode]: i18next.t("Rating Panel"),
35+
[PanelModeCodes.reportsMode]: i18next.t("Reports Panel"),
36+
[PanelModeCodes.playerMode]: i18next.t("Player Panel"),
37+
[PanelModeCodes.leaderboardMode]: i18next.t("Leaderboard"),
38+
[PanelModeCodes.topUserByClansMode]: i18next.t("Top users by clan ranking"),
39+
[PanelModeCodes.taskRatingMode]: i18next.t("Tasks ranking"),
40+
[PanelModeCodes.clansBubbleDistributionMode]: i18next.t(
41+
"Clans bubble distribution",
42+
),
43+
[PanelModeCodes.taskRatingAdvanced]: i18next.t(
44+
"Duration distribution and top users by task",
45+
),
46+
[PanelModeCodes.taskDurationDistributionMode]: i18next.t(
47+
"task duration distribution",
48+
),
49+
[PanelModeCodes.topUserByTasksMode]: i18next.t("Top user by task ranking"),
4550
};
4651

4752
const customStyle = {
48-
control: provided => ({
53+
control: (provided) => ({
4954
...provided,
50-
color: 'white',
51-
borderRadius: '0.3rem',
52-
backgroundColor: '#2a2a35',
53-
borderColor: '#3a3f50',
55+
color: "white",
56+
borderRadius: "0.3rem",
57+
backgroundColor: "#2a2a35",
58+
borderColor: "#3a3f50",
5459

55-
':hover': {
56-
borderColor: '#4c4c5a',
60+
":hover": {
61+
borderColor: "#4c4c5a",
5762
},
5863
}),
59-
indicatorsContainer: provided => ({
64+
indicatorsContainer: (provided) => ({
6065
...provided,
6166
}),
62-
indicatorSeparator: provided => ({
67+
indicatorSeparator: (provided) => ({
6368
...provided,
64-
backgroundColor: '#999',
69+
backgroundColor: "#999",
6570
}),
66-
clearIndicator: provided => ({
71+
clearIndicator: (provided) => ({
6772
...provided,
6873
}),
69-
dropdownIndicator: provided => ({
74+
dropdownIndicator: (provided) => ({
7075
...provided,
71-
color: '#999',
76+
color: "#999",
7277
}),
73-
input: provided => ({
78+
input: (provided) => ({
7479
...provided,
7580
}),
76-
menu: provided => ({
81+
menu: (provided) => ({
7782
...provided,
78-
backgroundColor: '#2a2a35',
83+
backgroundColor: "#2a2a35",
7984
}),
80-
option: provided => ({
85+
option: (provided) => ({
8186
...provided,
82-
backgroundColor: '#2a2a35',
83-
':hover': {
84-
backgroundColor: '#3a3f50',
87+
backgroundColor: "#2a2a35",
88+
":hover": {
89+
backgroundColor: "#3a3f50",
8590
},
86-
':focus': {
87-
backgroundColor: '#3a3f50',
91+
":focus": {
92+
backgroundColor: "#3a3f50",
8893
},
89-
':active': {
90-
backgroundColor: '#3a3f50',
94+
":active": {
95+
backgroundColor: "#3a3f50",
9196
},
9297
}),
9398
};
9499

95100
function ControlPanel({
101+
allowedPanelModes,
96102
isPlayer,
97103
searchOption,
98104
panelMode,
99105
panelHistory,
100-
disabledPanelModeControl = false,
101106
disabledSearch = false,
102107
setPanelHistory,
103108
setSearchOption,
104109
setPanelMode,
105110
}) {
111+
console.log(allowedPanelModes);
106112
const allPlayers = useSelector(tournamentPlayersSelector);
107113
const hasCustomEventStyles = useContext(CustomEventStylesContext);
108114

@@ -117,22 +123,31 @@ function ControlPanel({
117123
if (prev.userId) {
118124
setSearchOption(allPlayers[prev.userId]);
119125
}
120-
}, [panelHistory, setPanelHistory, setPanelMode, setSearchOption, allPlayers]);
121-
const onChangePanelMode = useCallback(e => {
122-
setPanelMode({ panel: e.target.value });
123-
setPanelHistory(items => [...items, panelMode]);
124-
}, [setPanelMode, setPanelHistory, panelMode]);
126+
}, [
127+
panelHistory,
128+
setPanelHistory,
129+
setPanelMode,
130+
setSearchOption,
131+
allPlayers,
132+
]);
133+
const onChangePanelMode = useCallback(
134+
(e) => {
135+
setPanelMode({ panel: e.target.value });
136+
setPanelHistory((items) => [...items, panelMode]);
137+
},
138+
[setPanelMode, setPanelHistory, panelMode],
139+
);
125140
const onChangeSearchedPlayer = useCallback(
126141
({ value = {} }) => setSearchOption(value),
127142
[setSearchOption],
128143
);
129144
const loadOptions = useCallback(
130145
(inputValue, callback) => {
131-
const substr = (inputValue || '').toLowerCase();
146+
const substr = (inputValue || "").toLowerCase();
132147

133148
const options = Object.values(allPlayers)
134-
.filter(player => player.name.toLowerCase().indexOf(substr) !== -1)
135-
.map(player => ({
149+
.filter((player) => player.name.toLowerCase().indexOf(substr) !== -1)
150+
.map((player) => ({
136151
label: <UserLabel user={player} />,
137152
value: player,
138153
}));
@@ -142,9 +157,9 @@ function ControlPanel({
142157
[allPlayers],
143158
);
144159

145-
const backBtnClassName = cn('btn text-nowrap cb-rounded mr-1 mb-2', {
146-
'btn-outline-secondary cb-btn-outline-secondary': !hasCustomEventStyles,
147-
'cb-custom-event-btn-outline-secondary': hasCustomEventStyles,
160+
const backBtnClassName = cn("btn text-nowrap cb-rounded mr-1 mb-2", {
161+
"btn-outline-secondary cb-btn-outline-secondary": !hasCustomEventStyles,
162+
"cb-custom-event-btn-outline-secondary": hasCustomEventStyles,
148163
});
149164

150165
return (
@@ -157,12 +172,15 @@ function ControlPanel({
157172
disabled={panelHistory.length === 0}
158173
>
159174
<FontAwesomeIcon icon="backward" className="mr-1" />
160-
{i18next.t('Back')}
175+
{i18next.t("Back")}
161176
</button>
162177
{panelMode.panel === PanelModeCodes.ratingMode && !disabledSearch ? (
163178
<div className="input-group flex-nowrap mb-2">
164179
<div className="input-group-prepend">
165-
<span className="input-group-text cb-bg-highlight-panel cb-border-color cb-text" id="search-icon">
180+
<span
181+
className="input-group-text cb-bg-highlight-panel cb-border-color cb-text"
182+
id="search-icon"
183+
>
166184
<FontAwesomeIcon icon="search" />
167185
</span>
168186
</div>
@@ -181,35 +199,35 @@ function ControlPanel({
181199
loadOptions={loadOptions}
182200
/>
183201
</div>
184-
) : <div />}
202+
) : (
203+
<div />
204+
)}
185205
</div>
186-
<div
187-
className={cn('d-flex mb-2 text-nowrap justify-content-end', {
188-
'text-muted': disabledPanelModeControl,
189-
})}
190-
>
206+
<div className={cn("d-flex mb-2 text-nowrap justify-content-end")}>
191207
<select
192208
key="select_panel_mode"
193209
className="form-control custom-select cb-bg-panel cb-border-color text-white cb-rounded"
194210
value={panelMode.panel}
195211
onChange={onChangePanelMode}
196-
disabled={disabledPanelModeControl}
197212
>
198-
{Object.values(PanelModeCodes).map(mode => (
199-
(![
200-
PanelModeCodes.taskRatingAdvanced,
201-
PanelModeCodes.taskDurationDistributionMode,
202-
PanelModeCodes.topUserByTasksMode,
203-
].includes(mode) || mode === panelMode.panel) && (
204-
<option
205-
key={mode}
206-
value={mode}
207-
className="cb-bg-panel text-white"
208-
disabled={mode === PanelModeCodes.playerMode && !isPlayer}
209-
>
210-
{mapPanelModeToTitle[mode]}
211-
</option>
212-
)))}
213+
{Object.values(PanelModeCodes).map(
214+
(mode) =>
215+
(![
216+
PanelModeCodes.taskRatingAdvanced,
217+
PanelModeCodes.taskDurationDistributionMode,
218+
PanelModeCodes.topUserByTasksMode,
219+
].includes(mode) ||
220+
mode === panelMode.panel) && (
221+
<option
222+
key={mode}
223+
value={mode}
224+
className="cb-bg-panel text-white"
225+
disabled={mode === PanelModeCodes.playerMode && !isPlayer}
226+
>
227+
{mapPanelModeToTitle[mode]}
228+
</option>
229+
),
230+
)}
213231
</select>
214232
</div>
215233
</div>

0 commit comments

Comments
 (0)