Skip to content

Commit 0d83b12

Browse files
committed
some fixes and new network machine
1 parent 9b3d38a commit 0d83b12

8 files changed

Lines changed: 68 additions & 26 deletions

File tree

services/app/assets/js/widgets/components/ExecutionOutput/AccordeonBox.jsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,20 @@ const SubMenu = ({
146146
);
147147
};
148148

149-
const Item = ({ output }) => (
150-
<div className="alert alert-secondary mb-0">
151-
<pre>
152-
<span className="font-weight-bold d-block">Output:</span>
153-
{output}
154-
</pre>
155-
</div>
156-
);
149+
const Item = ({ output }) => {
150+
if (output === '') {
151+
return <></>;
152+
}
153+
154+
return (
155+
<div className="alert alert-secondary mb-0">
156+
<pre>
157+
<span className="font-weight-bold d-block">Output:</span>
158+
{output}
159+
</pre>
160+
</div>
161+
);
162+
};
157163

158164
AccordeonBox.Item = Item;
159165
AccordeonBox.Menu = Menu;

services/app/assets/js/widgets/components/ExecutionOutput/Output.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const Output = ({ sideOutput }) => {
1212
const normalizedAsserts = version === 2 ? asserts : asserts.map(elem => camelizeKeys(JSON.parse(elem)));
1313
return (
1414
<>
15-
{status === 'error' || status === 'memory_leak' ? (
15+
{['error', 'memory_leak', 'timeout'].includes(status) ? (
1616
<AccordeonBox.Item output={output} result={result} />
1717
) : (
1818
normalizedAsserts

services/app/assets/js/widgets/components/ExecutionOutput/OutputTab.jsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import React from 'react';
22
import color from '../../config/statusColor';
33
import i18n from '../../../i18n';
44

5-
const getMessageLeftSide = status => {
5+
const getMessage = status => {
66
switch (status) {
7+
case 'timeout':
8+
return i18n.t('We couldn\'t retrieve check results. Check your network connection or your solution for bugs. =)');
79
case 'error':
810
return i18n.t('You have some syntax errors');
911
case 'failure':
@@ -14,24 +16,12 @@ const getMessageLeftSide = status => {
1416
return i18n.t('Press Check solution or press Give up');
1517
}
1618
};
17-
const getMessageRightSide = status => {
18-
switch (status) {
19-
case 'error':
20-
return i18n.t('You have some syntax errors');
21-
case 'failure':
22-
return i18n.t('Test failed');
23-
case 'ok':
24-
return i18n.t('Yay! All tests passed!!111');
25-
default:
26-
return 'No checks were started';
27-
}
28-
};
2919

3020
const OutputTab = ({ sideOutput, side }) => {
3121
const { successCount, assertsCount, status } = sideOutput;
3222
const isShowMessage = status === 'failure';
3323
const statusColor = color[status];
34-
const message = side === 'left' ? getMessageLeftSide(status) : getMessageRightSide(status);
24+
const message = getMessage(status);
3525
const percent = (100 * successCount) / assertsCount;
3626

3727
const assertsStatusMessage = i18n.t(

services/app/assets/js/widgets/containers/EditorContainer.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useMachine } from '@xstate/react';
66
import editorModes from '../config/editorModes';
77
import EditorToolbar from './EditorsToolbars/EditorToolbar';
88
import * as GameActions from '../middlewares/Game';
9+
import { actions } from '../slices';
910
import * as selectors from '../selectors';
1011
import GameContext from './GameContext';
1112
import { replayerMachineStates } from '../machines/game';
@@ -35,6 +36,17 @@ const EditorContainer = ({
3536
userStartChecking: () => {
3637
dispatch(GameActions.checkGameResult());
3738
},
39+
handleTimeoutFailureChecking: () => {
40+
dispatch(actions.updateExecutionOutput({
41+
userId: id,
42+
status: 'timeout',
43+
output: '',
44+
result: {},
45+
asserts: [],
46+
}));
47+
48+
dispatch(actions.updateCheckStatus({ [id]: false }));
49+
},
3850
},
3951
};
4052

services/app/assets/js/widgets/lib/player.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ export const resolveDiffs = (playbook, type) => {
317317
playbook.records,
318318
record => record.type === 'init',
319319
);
320+
// record types "init"
320321
const initGameState = {
321322
type,
322323
players: initRecords,

services/app/assets/js/widgets/machines/editor.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ const editor = {
7373
checking: {
7474
entry: initContextByState('checking'),
7575
after: {
76-
30000: {
76+
20000: {
7777
target: 'idle',
78-
actions: ['soundFailureChecking'],
78+
actions: ['soundFailureChecking', 'handleTimeoutFailureChecking'],
7979
},
8080
},
8181
on: {
@@ -85,8 +85,8 @@ const editor = {
8585
cond: 'isUserEvent',
8686
},
8787
},
88-
baned: {},
8988
},
89+
baned: {},
9090
},
9191
};
9292

@@ -97,6 +97,7 @@ export const config = {
9797
sound.play('check');
9898
},
9999
soundFailureChecking: () => {
100+
sound.stop();
100101
sound.play('failure');
101102
},
102103
soundFinishedChecking: () => {

services/app/assets/js/widgets/machines/game.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,27 @@ const machine = {
7171
speedMode: speedModes.normal,
7272
},
7373
states: {
74+
network: {
75+
initial: 'none',
76+
states: {
77+
none: {
78+
on: {
79+
JOIN: { target: 'connected' },
80+
FAILURE: { target: 'disconnected', actions: ['handleFailureJoin'] },
81+
},
82+
},
83+
disconnected: {
84+
on: {
85+
JOIN: { target: 'connected', actions: ['handleReconnection'] },
86+
},
87+
},
88+
connected: {
89+
on: {
90+
FAILURE: { target: 'disconnected', actions: ['handleDisconnection'] },
91+
},
92+
},
93+
},
94+
},
7495
game: {
7596
initial: 'preview',
7697
states: {
@@ -189,6 +210,10 @@ export const config = {
189210
throwError: (_ctx, { payload }) => {
190211
throw new Error(`Unexpected behavior (payload: ${JSON.stringify(payload)})`);
191212
},
213+
// network actions
214+
handleFailureJoin: () => {},
215+
handleDisconnection: () => {},
216+
handleReconnection: () => {},
192217

193218
// game actions
194219
soundWin: () => {

services/app/assets/js/widgets/middlewares/Game.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,17 @@ const initPlaybook = dispatch => data => {
104104
const initGameChannel = (dispatch, machine) => {
105105
const onJoinFailure = payload => {
106106
machine.send('REJECT_LOADING_GAME', { payload });
107+
machine.send('FAILURE_JOIN', { payload });
107108
window.location.reload();
108109
};
109110

111+
channel.onError(() => {
112+
machine.send('FAILURE');
113+
});
114+
110115
const onJoinSuccess = response => {
116+
machine.send('JOIN', { payload: response });
117+
111118
const {
112119
status,
113120
startsAt,

0 commit comments

Comments
 (0)