Skip to content

Commit 04b00ec

Browse files
committed
Update Notification UI/UX
- Update RunOptions to Play AI and SELF matches - Integrate Lock Code
1 parent 408e484 commit 04b00ec

6 files changed

Lines changed: 61 additions & 30 deletions

File tree

src/app/apiFetch/Submission.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* tslint:disable:no-console*/
2+
import { jsonResponseWrapper, setRequestHeaders } from 'app/apiFetch/utils';
23
import { API_BASE_URL } from '../../config/config';
34

45
export const codeCompile = (commitHash = 'latest') => {
@@ -101,15 +102,12 @@ export const executeDebugRun = (code: string, mapId: number, type: string, commi
101102
};
102103

103104
export const lockCode = () => {
104-
return fetch(`${API_BASE_URL}code/lock`, {
105+
return fetch(`${API_BASE_URL}code/submit`, {
105106
credentials: 'include',
106-
headers: {
107-
Accept: 'application/json',
108-
'Content-Type': 'application/json',
109-
},
110-
method: 'POST',
107+
headers: setRequestHeaders(),
108+
method: 'PUT',
111109
})
112-
.then((response) => response.json())
110+
.then((response) => jsonResponseWrapper(response))
113111
.then((data) => data)
114112
.catch((error) => {
115113
console.error(error);

src/app/components/SocketHandler.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,20 @@ export class SocketHandler extends React.Component<SocketHandlerInterfaces.Props
5151
}
5252
});
5353

54-
// tslint:disable-next-line: no-shadowed-variable
55-
const { updateGameLog, updateMatchPlayerId, userId } = this.props;
54+
const {
55+
updateGameLog,
56+
updateMatchPlayerId,
57+
// tslint:disable-next-line: no-shadowed-variable
58+
userId,
59+
clearDisplayDebugLog,
60+
clearAllLogs,
61+
} = this.props;
5662
const matchPlayerId = parseInt(matchDetails.matchPlayerId, 10);
5763
// tslint:disable-next-line: no-console
5864
console.log(matchDetails, matchPlayerId, userId);
5965

66+
clearDisplayDebugLog();
67+
clearAllLogs();
6068
updateGameLog('', '', '');
6169
updateGameLog(matchDetails.debugLog1, matchDetails.debugLog2, matchDetails.gameLog);
6270
updateMatchPlayerId(matchPlayerId === userId ? 1 : 2);

src/app/components/SubmitBar/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ export class SubmitBar extends React.Component<
172172
className={classnames(styles.customBtn)}
173173
title="Submit Code"
174174
id="submit_button"
175-
onClick={this.props.lockCode}
175+
onClick={(e) => {
176+
this.props.saveCode();
177+
this.props.lockCode();
178+
}}
176179
>
177180
<span className={classnames(styles.icon)}>
178181
<FontAwesomeIcon icon={faLock} />

src/app/containers/SocketHandler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const mapStateToProps = (rootState: RootState) => {
1111

1212
const mapDispatchToProps = (dispatch: Dispatch) => {
1313
return {
14+
clearAllLogs: () => GameLogActions.clearAllLogs(),
15+
clearDisplayDebugLog: () => GameLogActions.clearDisplayDebugLog(),
1416
sendCompileError: (error: string) => dispatch(SubmissionActions.handleCompileError(error)),
1517
sendCompileSuccess: () => dispatch(SubmissionActions.handleCompileSuccess()),
1618
sendDebugRunError: () => dispatch(SubmissionActions.handleDebugRunError()),

src/app/sagas/Submission.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* tslint:disable:no-console*/
2-
import { CodeActions, GameLogActions, SubmissionActions } from 'app/actions';
2+
import { CodeActions, GameLogActions, NotificationActions, 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';
@@ -11,25 +11,15 @@ export const getSubmissionState = (state: RootState) => state.submission;
1111
export const getUserLatestCode = (state: RootState) => state.code.code;
1212

1313
export function* lockCode(action: ActionType<typeof SubmissionActions.lockCode>) {
14-
// try {
15-
// const submissionState = yield select(getSubmissionState);
16-
// if (submissionState.request !== Request.NONE) return;
17-
// yield put(SubmissionActions.updateDebugRunRequest(Request.NONE));
18-
// yield put(CodeActions.save());
19-
// yield put(NotificationActions.info('Code is being locked...'));
20-
// yield put(GameLogActions.clearAllLogs());
21-
// yield put(GameLogActions.setHideDebugLog(false));
22-
// yield put(
23-
// SubmissionActions.changeStateCurrentRequest(
24-
// RequestState.COMPILE_CURRENT_CODE,
25-
// Request.LOCK_CODE,
26-
// '',
27-
// 0,
28-
// ),
29-
// );
30-
// } catch (err) {
31-
// console.error(err);
32-
// }
14+
try {
15+
yield put(CodeActions.save());
16+
// @ts-ignore
17+
const res = yield call(SubmissionFetch.lockCode);
18+
yield put(NotificationActions.success('Code Locked'));
19+
yield put(GameLogActions.clearAllLogs());
20+
} catch (err) {
21+
console.error(err);
22+
}
3323
}
3424

3525
export function* previousCommitMatch(

src/app/types/SocketHandler.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,36 @@ export interface DispatchProps {
88
sendError: (message: string) => void;
99
sendInfo: (message: string) => void;
1010
sendSuccess: (message: string) => void;
11+
updateRequest: (request: SubmissionInterfaces.Request) => void;
12+
updateGameLog: (player1DebugLog: string, player2DebugLog: string, gameLog: string) => void;
13+
updateMatchPlayerId: (matchPlayerId: number) => void;
14+
clearDisplayDebugLog: () => void;
15+
clearAllLogs: () => void;
16+
}
17+
18+
export enum MatchMode {
19+
AUTO = 'AUTO',
20+
SELF = 'SELF',
21+
AI = 'AI',
22+
PREV_COMMIT = 'PREV_COMMIT',
23+
MANUAL = 'MANUAL',
24+
}
25+
26+
export interface MatchDetails {
27+
mapId: number;
28+
matchMode: MatchMode;
29+
playerId1: number;
30+
playerId2: number;
31+
}
32+
33+
export interface StateProps {
34+
commitHash: string;
35+
currentAiId: number;
36+
mapId: number;
37+
playerId1: number;
38+
playerId2: number;
39+
request: SubmissionInterfaces.Request;
40+
userId: number;
1141
}
1242

1343
export type Props = DispatchProps;

0 commit comments

Comments
 (0)