Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit def07d1

Browse files
committed
Add socket route for code submission
1 parent d1e8e7f commit def07d1

File tree

8 files changed

+62
-17
lines changed

8 files changed

+62
-17
lines changed

src/app/actions/code/Submission.ts

+3
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

+11
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ export class SocketHandler extends React.Component<SocketHandlerInterfaces.Props
109109
);
110110
}
111111

112+
public lockCode(): void {
113+
// @ts-ignore
114+
this.stompClient.send('/socket/request/code/submit');
115+
this.props.toggleLockCode();
116+
}
117+
112118
public componentDidUpdate() {
113119
const {
114120
request,
@@ -118,6 +124,7 @@ export class SocketHandler extends React.Component<SocketHandlerInterfaces.Props
118124
currentAiId,
119125
updateRequest,
120126
userId,
127+
isCodeLocked,
121128
} = this.props;
122129
switch (request) {
123130
case SubmissionInterfaces.Request.PREVIOUS_COMMIT_MATCH: {
@@ -170,6 +177,10 @@ export class SocketHandler extends React.Component<SocketHandlerInterfaces.Props
170177
updateRequest(SubmissionInterfaces.Request.NONE);
171178
}
172179
}
180+
181+
if (isCodeLocked) {
182+
this.lockCode();
183+
}
173184
}
174185

175186
public componentWillUnmount(): void {

src/app/components/SubmitBar/RunOptions.tsx

+14-13
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';
@@ -49,9 +49,10 @@ export class RunOptions extends React.Component<
4949

5050
const maps = this.props.maps || hardCodedMap;
5151

52-
const hardCodedAiIds: number[] = [1];
52+
// const hardCodedAiIds: number[] = [1];
5353

54-
const aiIds = hardCodedAiIds;
54+
// @ts-ignore
55+
// const aiIds = hardCodedAiIds;
5556

5657
const matchOptions = [
5758
{
@@ -62,16 +63,16 @@ export class RunOptions extends React.Component<
6263
},
6364
];
6465

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

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

src/app/containers/SocketHandler.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,22 @@ import { connect } from 'react-redux';
66
import { Dispatch } from 'redux';
77

88
const mapStateToProps = (rootState: RootState) => {
9-
return {};
9+
return {
10+
announcements: rootState.notification.announcements,
11+
commitHash: rootState.submission.commitHash,
12+
currentAiId: rootState.submission.currentAiId,
13+
isCodeLocked: rootState.submission.isCodeLocked,
14+
isNotificationPresent: rootState.user.isNotificationPresent,
15+
isSocketPresent: rootState.user.isSocketPresent,
16+
loading: rootState.notification.loading,
17+
mapId: rootState.submission.mapId,
18+
notifications: rootState.notification.notifications,
19+
playerId1: rootState.submission.playerId1,
20+
playerId2: rootState.submission.playerId2,
21+
request: rootState.submission.request,
22+
socketMessage: rootState.user.socketMessage,
23+
userId: rootState.user.userId,
24+
};
1025
};
1126

1227
const mapDispatchToProps = (dispatch: Dispatch) => {
@@ -24,6 +39,7 @@ const mapDispatchToProps = (dispatch: Dispatch) => {
2439
sendInfo: (message: string) => dispatch(NotificationActions.info(message)),
2540
sendSuccess: (message: string) => dispatch(NotificationActions.success(message)),
2641
success: (message: string) => dispatch(NotificationActions.success(message)),
42+
toggleLockCode: () => dispatch(SubmissionActions.toggleLockCode()),
2743
updateDisplayDebugLog: (log: string) => dispatch(GameLogActions.updateDisplayDebugLog(log)),
2844
updateGameLog: (player1DebugLog: string, player2DebugLog: string, gameLog: string) =>
2945
dispatch(GameLogActions.updateGameLog(player1DebugLog, player2DebugLog, gameLog)),

src/app/reducers/code/Submission.ts

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const submissionStoreState: SubmissionInterfaces.SubmissionStoreState = {
77
debugRunCode: '',
88
debugRunCommitHash: 'latest',
99
debugRunRequest: SubmissionInterfaces.Request.NONE,
10+
isCodeLocked: false,
1011
mapId: 1,
1112
maps: [],
1213
request: SubmissionInterfaces.Request.NONE,
@@ -88,6 +89,11 @@ export const submissionReducer = (
8889
return {
8990
...submissionStoreState,
9091
};
92+
case SubmissionActions.Type.TOGGLE_LOCK_CODE:
93+
return {
94+
...submissionStoreState,
95+
isCodeLocked: !state.isCodeLocked,
96+
};
9197
default:
9298
return state;
9399
}

src/app/sagas/Submission.ts

+4-3
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

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface DispatchProps {
99
sendInfo: (message: string) => void;
1010
sendSuccess: (message: string) => void;
1111
success: (message: string) => void;
12+
toggleLockCode: () => void;
1213
updateDisplayDebugLog: (log: string) => void;
1314
updateGameLog: (player1DebugLog: string, player2DebugLog: string, gameLog: string) => void;
1415
updateMatchPlayerId: (matchPlayerId: number) => void;
@@ -39,6 +40,7 @@ export interface StateProps {
3940
playerId2: number;
4041
request: SubmissionInterfaces.Request;
4142
userId: number;
43+
isCodeLocked: boolean;
4244
}
4345

4446
export type Props = DispatchProps;

src/app/types/code/Submission.ts

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const actions = {
66
changeState: SubmissionActions.changeState,
77
resetSubmissionState: SubmissionActions.resetSubmissionState,
88
saveMaps: SubmissionActions.saveMaps,
9+
toggleLockCode: SubmissionActions.toggleLockCode,
910
updateAiIds: SubmissionActions.updateAiIds,
1011
updateCommitHash: SubmissionActions.updateCommitHash,
1112
updateCurrentAiId: SubmissionActions.updateCurrentAiId,
@@ -46,6 +47,10 @@ export interface SubmissionStoreState {
4647
debugRunCommitHash: string;
4748
mapId: number;
4849
maps: Map[];
50+
commitHash: string;
51+
playerId1: number;
52+
playerId2: number;
53+
isCodeLocked: boolean;
4954
}
5055

5156
export interface Map {

0 commit comments

Comments
 (0)