Skip to content

Commit 039ad17

Browse files
committed
refactor round progress statistics
1 parent 71d11bf commit 039ad17

File tree

15 files changed

+231
-107
lines changed

15 files changed

+231
-107
lines changed

services/app/apps/codebattle/assets/js/widgets/components/Editor.jsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class Editor extends PureComponent {
3030
onChange: PropTypes.func,
3131
mode: PropTypes.string.isRequired,
3232
mute: PropTypes.bool,
33+
fontSize: PropTypes.number,
3334
};
3435

3536
static defaultProps = {
@@ -40,6 +41,7 @@ class Editor extends PureComponent {
4041
onChange: null,
4142
syntax: 'js',
4243
mute: false,
44+
fontSize: 16,
4345
};
4446

4547
// eslint-disable-next-line react/sort-comp
@@ -59,7 +61,7 @@ class Editor extends PureComponent {
5961
tabSize: getLanguageTabSize(props.syntax),
6062
insertSpaces: shouldReplaceTabsWithSpaces(props.syntax),
6163
lineNumbersMinChars: 3,
62-
fontSize: 16,
64+
fontSize: props.fontSize || 16,
6365
scrollBeyondLastLine: false,
6466
selectOnLineNumbers: true,
6567
minimap: {
@@ -133,6 +135,7 @@ class Editor extends PureComponent {
133135
userId,
134136
gameId,
135137
gameMode,
138+
fontSize,
136139
} = this.props;
137140

138141
const isBuilder = gameMode === GameRoomModes.builder;
@@ -160,6 +163,13 @@ class Editor extends PureComponent {
160163
this.statusBarRef.current.innerHTML = '';
161164
this.currentMode = this.modes[mode]();
162165
}
166+
if (prevProps.fontSize !== fontSize) {
167+
this.options = {
168+
...this.options,
169+
fontSize: fontSize || 16,
170+
};
171+
this.editor.updateOptions(this.options);
172+
}
163173
if (prevProps.editable !== editable || prevProps.loading !== loading) {
164174
this.options = {
165175
...this.options,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const initTournamentPlayerChannel = dispatch => {
2222
state: data.tournamentState,
2323
breakState: data.breakState,
2424
matches: data.matches,
25+
gameResults: data.gameResults,
2526
tournamentChannel: { online: true },
2627
}));
2728

@@ -46,6 +47,7 @@ export const connectToTournamentPlayer = () => dispatch => {
4647

4748
dispatch(actions.updateTournamentData({ state: data.state, breakState: data.breakState }));
4849
dispatch(actions.updateTournamentMatches(data.matches));
50+
dispatch(actions.updateTournamentGameResults(data.gameResults));
4951
};
5052

5153
const handleTournamentRoundCreated = response => {

services/app/apps/codebattle/assets/js/widgets/pages/builder/BuilderEditorsWidget.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ function BuilderEditorsWidget() {
9797
);
9898
const textSolution = useSelector(selectors.taskTextSolutionSelector);
9999
const currentUserId = useSelector(selectors.currentUserIdSelector);
100-
const theme = useSelector(selectors.editorsThemeSelector(currentUserId));
101-
const editorsMode = useSelector(selectors.editorsModeSelector(currentUserId));
100+
const theme = useSelector(selectors.editorsThemeSelector);
101+
const editorsMode = useSelector(selectors.editorsModeSelector);
102102

103103
const [isValidArgumentsGenerator, invalidGeneratorReason] = useSelector(
104104
state => state.builder.validationStatuses.argumentsGenerator,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import editorThemes from '../../config/editorThemes';
77
import { editorsThemeSelector } from '../../selectors';
88
import { actions } from '../../slices';
99

10-
function DakModeButton({ playerId }) {
10+
function DakModeButton() {
1111
const dispatch = useDispatch();
1212

13-
const currentTheme = useSelector(state => editorsThemeSelector(playerId)(state));
13+
const currentTheme = useSelector(editorsThemeSelector);
1414

1515
const isDarkMode = currentTheme === editorThemes.dark;
1616
const mode = isDarkMode ? editorThemes.light : editorThemes.dark;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ function GameWidget({ editorMachine }) {
9393
const leftEditorHeight = useSelector(selectors.editorHeightSelector(roomCurrent, leftUserId));
9494
const rightEditorHeight = useSelector(selectors.editorHeightSelector(roomCurrent, rightUserId));
9595
const rightOutput = useSelector(selectors.rightExecutionOutputSelector(roomCurrent));
96-
const leftEditorsMode = useSelector(selectors.editorsModeSelector(leftUserId));
97-
const theme = useSelector(selectors.editorsThemeSelector(leftUserId));
96+
const leftEditorsMode = useSelector(selectors.editorsModeSelector);
97+
const theme = useSelector(selectors.editorsThemeSelector);
9898

9999
return (
100100
<>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import editorModes from '../../config/editorModes';
77
import { editorsModeSelector } from '../../selectors';
88
import { actions } from '../../slices';
99

10-
function VimModeButton({ playerId }) {
10+
function VimModeButton() {
1111
const dispatch = useDispatch();
12-
const currentMode = useSelector(state => editorsModeSelector(playerId)(state));
12+
const currentMode = useSelector(editorsModeSelector);
1313

1414
const isVimMode = currentMode === editorModes.vim;
1515

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

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -201,54 +201,55 @@ function TournamentHeader({
201201
</div>
202202
)}
203203
</div>
204-
{!isOver ? (
204+
<div className="d-flex">
205+
{!isOver ? (
206+
<div className="d-flex justify-items-center pb-2">
207+
{type !== 'team' && (
208+
<div className="mr-2 mr-lg-0">
209+
<JoinButton
210+
isShow={state !== TournamentStates.active}
211+
isParticipant={!!players[currentUserId]}
212+
disabled={!isOnline || !isLive}
213+
/>
214+
</div>
215+
)}
216+
</div>
217+
) : (
218+
<div className="d-flex justify-items-center pb-2">
219+
<a
220+
className="btn btn-primary rounded-lg ml-lg-2 ml-md-2"
221+
href="/tournaments"
222+
>
223+
<FontAwesomeIcon className="mr-2" icon="undo" />
224+
Return to tournaments
225+
</a>
226+
</div>
227+
)}
205228
<div className="d-flex justify-items-center pb-2">
206-
{type !== 'team' && (
207-
<div className="mr-2 mr-lg-0">
208-
<JoinButton
209-
isShow={state !== TournamentStates.active}
210-
isParticipant={!!players[currentUserId]}
211-
disabled={!isOnline || !isLive}
212-
/>
213-
</div>
229+
{canModerate && (
230+
<TournamentMainControlButtons
231+
accessType={accessType}
232+
tournamentId={tournamentId}
233+
canStart={
234+
isLive
235+
&& state === TournamentStates.waitingParticipants
236+
&& playersCount > 0
237+
}
238+
canStartRound={
239+
isLive
240+
&& state === TournamentStates.active
241+
&& breakState === 'on'
242+
}
243+
canRestart={
244+
state === TournamentStates.active
245+
|| state === TournamentStates.finished
246+
|| state === TournamentStates.cancelled
247+
}
248+
disabled={!isOnline}
249+
/>
214250
)}
215251
</div>
216-
) : (
217-
<div className="d-flex justify-items-center pb-2">
218-
<a
219-
className="btn btn-primary rounded-lg ml-lg-2 ml-md-2"
220-
href="/tournaments"
221-
>
222-
<FontAwesomeIcon className="mr-2" icon="undo" />
223-
Return to tournaments
224-
</a>
225-
</div>
226-
)}
227-
<div className="d-flex justify-items-center pb-2">
228-
{canModerate && (
229-
<TournamentMainControlButtons
230-
accessType={accessType}
231-
tournamentId={tournamentId}
232-
canStart={
233-
isLive
234-
&& state === TournamentStates.waitingParticipants
235-
&& playersCount > 0
236-
}
237-
canStartRound={
238-
isLive
239-
&& state === TournamentStates.active
240-
&& breakState === 'on'
241-
}
242-
canRestart={
243-
state === TournamentStates.active
244-
|| state === TournamentStates.finished
245-
|| state === TournamentStates.cancelled
246-
}
247-
disabled={!isOnline}
248-
/>
249-
)}
250252
</div>
251-
252253
</div>
253254
<div className="d-flex align-items-center small text-nowrap text-muted mt-1 cb-grid-divider overflow-auto">
254255
<div title={type} className="d-flex align-items-center">

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const TournamentMainControlButtons = ({
3939
onClick={handleStartRoundTournament}
4040
disabled={!canStartRound || disabled}
4141
>
42-
<FontAwesomeIcon className="ml-2" icon="arrow-right" />
42+
<FontAwesomeIcon className="mr-2" icon="arrow-right" />
4343
Start Round
4444
</button>
4545
) : null}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function TournamentUserPanel({
1818
userId,
1919
name,
2020
score,
21-
place,
21+
// place,
2222
localPlace,
2323
searchedUserId = 0,
2424
}) {
@@ -77,16 +77,16 @@ function TournamentUserPanel({
7777
{': '}
7878
{score}
7979
</span>
80-
{place && (
81-
<>
82-
<span className="mx-1">|</span>
83-
<span title="Place on tournament">
84-
<FontAwesomeIcon className="text-warning" icon="trophy" />
85-
{': '}
86-
{place}
87-
</span>
88-
</>
89-
)}
80+
{/* {place && ( */}
81+
{/* <> */}
82+
{/* <span className="mx-1">|</span> */}
83+
{/* <span title="Place on tournament"> */}
84+
{/* <FontAwesomeIcon className="text-warning" icon="trophy" /> */}
85+
{/* {': '} */}
86+
{/* {place} */}
87+
{/* </span> */}
88+
{/* </> */}
89+
{/* )} */}
9090
{localPlace && (
9191
<>
9292
<span className="mx-1">|</span>

services/app/apps/codebattle/assets/js/widgets/pages/tournamentPlayer/SpectatorEditor.jsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { memo } from 'react';
1+
import React, { memo, useState, useCallback } from 'react';
22

33
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
44
import cn from 'classnames';
@@ -28,12 +28,17 @@ function SpectatorEditor({
2828
const players = useSelector(selectors.gamePlayersSelector);
2929
const editorData = useSelector(selectors.editorDataSelector(playerId));
3030
const currentUserId = useSelector(selectors.currentUserIdSelector);
31-
const theme = useSelector(selectors.editorsThemeSelector(currentUserId));
32-
const editorsMode = useSelector(selectors.editorsModeSelector(currentUserId));
31+
const theme = useSelector(selectors.editorsThemeSelector);
32+
const editorsMode = useSelector(selectors.editorsModeSelector);
3333

3434
const spectatorEditorState = useMachineStateSelector(spectatorService, spectatorStateSelector).value.editor;
3535
const isChecking = useMachineStateSelector(spectatorService, spectatorEditorIsChecking);
3636

37+
const [fontSize, setFontSize] = useState(20);
38+
39+
const handleIncreaseFontSize = useCallback(() => setFontSize(size => size + 2), [setFontSize]);
40+
const handleDecreaseFontSize = useCallback(() => setFontSize(size => size - 2), [setFontSize]);
41+
3742
const params = {
3843
userId: spectatorEditorState === 'loading' ? undefined : playerId,
3944
editable: false,
@@ -42,9 +47,10 @@ function SpectatorEditor({
4247
loading: spectatorEditorState === 'loading',
4348
theme,
4449
mute: true,
50+
fontSize,
4551
};
4652

47-
const solutionParams = {
53+
const editorParams = {
4854
...params,
4955
value: editorData?.text || '',
5056
onChange: () => {},
@@ -58,7 +64,7 @@ function SpectatorEditor({
5864
<>
5965
<div className={pannelBackground} data-editor-state={spectatorEditorState}>
6066
<div className="card h-100 shadow-sm" style={gameRoomEditorStyles}>
61-
<div className="rounded-top" data-player-type="current_user">
67+
<div className="rounded-top border-bottom">
6268
<div className="btn-toolbar justify-content-between align-items-center m-1" role="toolbar">
6369
<div className="d-flex justify-content-between">
6470
<div className="d-flex align-items-center p-1">
@@ -84,6 +90,18 @@ function SpectatorEditor({
8490
<VimModeButton playerId={currentUserId} />
8591
<DakModeButton playerId={currentUserId} />
8692
</div>
93+
<div
94+
className="btn-group align-items-center ml-2 mr-auto"
95+
role="group"
96+
aria-label="Editor size controls"
97+
>
98+
<button type="button" className="btn btn-sm btn-light rounded-left" onClick={handleIncreaseFontSize}>
99+
-
100+
</button>
101+
<button type="button" className="btn btn-sm mr-2 btn-light border-left rounded-right" onClick={handleDecreaseFontSize}>
102+
+
103+
</button>
104+
</div>
87105
</div>
88106
<div className="d-flex">
89107
<button
@@ -102,7 +120,7 @@ function SpectatorEditor({
102120
</div>
103121
</div>
104122
<div id="spectator" className="d-flex flex-column flex-grow-1 position-relative">
105-
<Editor {...solutionParams} />
123+
<Editor {...editorParams} />
106124
</div>
107125
</div>
108126
</div>

0 commit comments

Comments
 (0)