Skip to content

Commit 31bf971

Browse files
committed
Add socket route for code submission
1 parent 89adf1a commit 31bf971

File tree

8 files changed

+43
-16
lines changed

8 files changed

+43
-16
lines changed

src/app/actions/code/Submission.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export namespace SubmissionActions {
2929
UPDATE_COMMIT_HASH = 'UPDATE_COMMIT_HASH',
3030
UPDATE_PLAYER_ID2 = 'UPDATE_PLAYER_ID2',
3131
RESET_SUBMISSION_STATE = 'RESET_SUBMISSION_STATE',
32+
TOGGLE_LOCK_CODE = 'TOGGLE_LOCK_CODE',
3233
}
3334

3435
export const changeState = (state: SubmissionInterfaces.RequestState) =>
@@ -107,4 +108,6 @@ export namespace SubmissionActions {
107108
export const updatePlayerId2 = (playerId2: number) => {
108109
return action(Type.UPDATE_PLAYER_ID2, { playerId2 });
109110
};
111+
112+
export const toggleLockCode = () => action(Type.TOGGLE_LOCK_CODE);
110113
}

src/app/components/SocketHandler.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ export class SocketHandler extends React.Component<SocketHandlerInterfaces.Props
120120
);
121121
}
122122

123+
public lockCode(): void {
124+
// @ts-ignore
125+
this.stompClient.send('/socket/request/code/submit');
126+
this.props.toggleLockCode();
127+
}
128+
123129
public componentDidUpdate() {
124130
// tslint:disable-next-line: no-console
125131
const {
@@ -130,6 +136,7 @@ export class SocketHandler extends React.Component<SocketHandlerInterfaces.Props
130136
currentAiId,
131137
updateRequest,
132138
userId,
139+
isCodeLocked,
133140
} = this.props;
134141
switch (request) {
135142
case SubmissionInterfaces.Request.PREVIOUS_COMMIT_MATCH: {
@@ -177,6 +184,10 @@ export class SocketHandler extends React.Component<SocketHandlerInterfaces.Props
177184
break;
178185
}
179186
}
187+
188+
if (isCodeLocked) {
189+
this.lockCode();
190+
}
180191
}
181192

182193
public componentWillUnmount(): void {

src/app/components/SubmitBar/RunOptions.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { faBrain, faRobot } from '@fortawesome/free-solid-svg-icons';
1+
import { faBrain } from '@fortawesome/free-solid-svg-icons';
22
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
33
import { SubmissionActions } from 'app/actions';
44
import * as styles from 'app/styles/RunOptions.module.css';
@@ -48,10 +48,10 @@ export class RunOptions extends React.Component<
4848

4949
const maps = hardCodedMap;
5050

51-
const hardCodedAiIds: number[] = [1];
51+
// const hardCodedAiIds: number[] = [1];
5252

5353
// @ts-ignore
54-
const aiIds = hardCodedAiIds;
54+
// const aiIds = hardCodedAiIds;
5555

5656
const matchOptions = [
5757
{
@@ -62,16 +62,16 @@ export class RunOptions extends React.Component<
6262
},
6363
];
6464

65-
if (aiIds) {
66-
aiIds.map((aiId) => {
67-
matchOptions.push({
68-
aiId,
69-
icon: <FontAwesomeIcon icon={faRobot} />,
70-
name: `AI ${aiId} Match`,
71-
type: SubmissionActions.Type.AI_MATCH,
72-
});
73-
});
74-
}
65+
// if (aiIds) {
66+
// aiIds.map((aiId) => {
67+
// matchOptions.push({
68+
// aiId,
69+
// icon: <FontAwesomeIcon icon={faRobot} />,
70+
// name: `AI ${aiId} Match`,
71+
// type: SubmissionActions.Type.AI_MATCH,
72+
// });
73+
// });
74+
// }
7575

7676
const mapOptions = (
7777
<div className={classnames(styles['dropdown-submenu'])}>

src/app/containers/SocketHandler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const mapStateToProps = (rootState: RootState) => {
1212
announcements: rootState.notification.announcements,
1313
commitHash: rootState.submission.commitHash,
1414
currentAiId: rootState.submission.currentAiId,
15+
isCodeLocked: rootState.submission.isCodeLocked,
1516
isNotificationPresent: rootState.user.isNotificationPresent,
1617
isSocketPresent: rootState.user.isSocketPresent,
1718
loading: rootState.notification.loading,
@@ -56,6 +57,7 @@ const mapDispatchToProps = (dispatch: Dispatch) => {
5657
sendInfo: (message: string) => dispatch(NotificationActions.info(message)),
5758
sendSuccess: (message: string) => dispatch(NotificationActions.success(message)),
5859
success: (message: string) => dispatch(NotificationActions.success(message)),
60+
toggleLockCode: () => dispatch(SubmissionActions.toggleLockCode()),
5961
updateDisplayDebugLog: (log: string) => dispatch(GameLogActions.updateDisplayDebugLog(log)),
6062
updateGameLog: (player1DebugLog: string, player2DebugLog: string, gameLog: string) =>
6163
dispatch(GameLogActions.updateGameLog(player1DebugLog, player2DebugLog, gameLog)),

src/app/reducers/code/Submission.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const submissionStoreState: SubmissionInterfaces.SubmissionStoreState = {
88
debugRunCode: '',
99
debugRunCommitHash: 'latest',
1010
debugRunRequest: SubmissionInterfaces.Request.NONE,
11+
isCodeLocked: false,
1112
mapId: 1,
1213
maps: [],
1314
playerId1: 1,
@@ -91,6 +92,11 @@ export const submissionReducer = (
9192
return {
9293
...submissionStoreState,
9394
};
95+
case SubmissionActions.Type.TOGGLE_LOCK_CODE:
96+
return {
97+
...submissionStoreState,
98+
isCodeLocked: !state.isCodeLocked,
99+
};
94100
default:
95101
return state;
96102
}

src/app/sagas/Submission.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* tslint:disable:no-console*/
2-
import { CodeActions, GameLogActions, NotificationActions, SubmissionActions } from 'app/actions';
2+
import { CodeActions, GameLogActions, SubmissionActions } from 'app/actions';
33
import * as SubmissionFetch from 'app/apiFetch/Submission';
44
import { RootState } from 'app/reducers';
55
import { checkAccountActivated, checkAuthentication } from 'app/sagas/utils';
@@ -14,8 +14,9 @@ export function* lockCode(action: ActionType<typeof SubmissionActions.lockCode>)
1414
try {
1515
yield put(CodeActions.save());
1616
// @ts-ignore
17-
const res = yield call(SubmissionFetch.lockCode);
18-
yield put(NotificationActions.success('Code Locked'));
17+
// const res = yield call(SubmissionFetch.lockCode);
18+
// yield put(NotificationActions.success('Code Locked'));
19+
yield put(SubmissionActions.toggleLockCode());
1920
yield put(GameLogActions.clearAllLogs());
2021
} catch (err) {
2122
console.error(err);

src/app/types/SocketHandler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface DispatchProps {
2626
sendInfo: (message: string) => void;
2727
sendSuccess: (message: string) => void;
2828
success: (message: string) => void;
29+
toggleLockCode: () => void;
2930
updateDisplayDebugLog: (log: string) => void;
3031
updateGameLog: (player1DebugLog: string, player2DebugLog: string, gameLog: string) => void;
3132
updateGlobalAnnouncements: (announcements: NotificationInterfaces.Announcement[]) => void;
@@ -63,6 +64,7 @@ export interface StateProps {
6364
request: SubmissionInterfaces.Request;
6465
socketMessage: string;
6566
userId: number;
67+
isCodeLocked: boolean;
6668
}
6769

6870
export type Props = DispatchProps & StateProps;

src/app/types/code/Submission.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const actions = {
77
logout: UserActions.logout,
88
resetSubmissionState: SubmissionActions.resetSubmissionState,
99
saveMaps: SubmissionActions.saveMaps,
10+
toggleLockCode: SubmissionActions.toggleLockCode,
1011
updateAiIds: SubmissionActions.updateAiIds,
1112
updateCommitHash: SubmissionActions.updateCommitHash,
1213
updateCurrentAiId: SubmissionActions.updateCurrentAiId,
@@ -50,6 +51,7 @@ export interface SubmissionStoreState {
5051
commitHash: string;
5152
playerId1: number;
5253
playerId2: number;
54+
isCodeLocked: boolean;
5355
}
5456

5557
export interface Map {

0 commit comments

Comments
 (0)