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

Commit dd45d36

Browse files
thetsajeetBLNDLYBLVdipeshkaphleram2091999
authored
Quest backend integration (#72)
* feat: Quest Dropdown * Add Pagination for notification messages * Added StoryModeModal component and actions to open and close the modal. Added isStoryModeModalOpen and storyModeModalLevel to global state * fix snapshot error * feat: rebase StoryModeModal and QuestDropDown * Change in UI of quest dropdown * Added startMatch onclick to StoryModeModal to run AI Matches * Fixed Lint Errors * Add Pagination for notification messages * Added StoryModeModal component and actions to open and close the modal. Added isStoryModeModalOpen and storyModeModalLevel to global state * chore: integrate with backend user-quest status api * Fix bug in quest dropdown menu * Add file questLevels to store quest data * Fix StoryModeModal to show description from questLevels.ts Co-authored-by: Sriram <sriram01201@gmail.com> Co-authored-by: Dipesh Kafle <dipesh.kaphle111@gmail.com> Co-authored-by: Ram <ram2091999@users.noreply.github.com>
1 parent 25926b6 commit dd45d36

23 files changed

+452
-6
lines changed

__tests__/app/components/EditPassword.test.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ describe('EditPassword Component', () => {
2121
avatar: '',
2222
college: '',
2323
country: 'IN',
24+
current_level: 1,
25+
current_stars: 1,
2426
email: '',
2527
errorMessage: '',
2628
fullName: '',
@@ -30,9 +32,12 @@ describe('EditPassword Component', () => {
3032
isLoginLoading: false,
3133
isNotificationPresent: false,
3234
isSocketPresent: false,
35+
isStoryModeModalOpen: false,
3336
isUserProfileModalOpen: false,
3437
notification: '',
38+
ratings: [],
3539
socketMessage: '',
40+
storyModeModalLevel: 0,
3641
userId: 0,
3742
userType: UserType.STUDENT,
3843
username: '',

__tests__/app/components/__snapshots__/EditPassword.test.tsx.snap

+5
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ exports[`EditPassword Component Should render 1`] = `
140140
"avatar": "",
141141
"college": "",
142142
"country": "IN",
143+
"current_level": 1,
144+
"current_stars": 1,
143145
"email": "",
144146
"errorMessage": "",
145147
"fullName": "",
@@ -149,9 +151,12 @@ exports[`EditPassword Component Should render 1`] = `
149151
"isLoginLoading": false,
150152
"isNotificationPresent": false,
151153
"isSocketPresent": false,
154+
"isStoryModeModalOpen": false,
152155
"isUserProfileModalOpen": false,
153156
"notification": "",
157+
"ratings": Array [],
154158
"socketMessage": "",
159+
"storyModeModalLevel": 0,
155160
"userId": 0,
156161
"userType": "STUDENT",
157162
"username": "",

src/app/actions/User.ts

+18
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export namespace UserActions {
88
LOGOUT = 'LOGOUT',
99
REGISTER = 'REGISTER',
1010
GET_USER_DETAILS = 'GET_USER_DETAILS',
11+
GET_USER_QUESTSTATUS = 'GET_USER_QUESTSTATUS',
12+
UPDATE_USER_QUESTSTATUS = 'UPDATE_USER_QUESTSTATUS',
13+
SET_CURRENT_LEVEL = 'SET_CURRENT_LEVEL',
1114
EDIT_USER_PROFILE = 'EDIT_USER_PROFILE',
1215
EDIT_USER_PASSWORD = 'EDIT_USER_PASSWORD',
1316
UPDATE_ERROR_MESSAGE = 'UPDATE_ERROR_MESSAGE',
@@ -23,6 +26,8 @@ export namespace UserActions {
2326
RESET_APP_STATE = 'RESET_APP_STATE',
2427
SET_IS_AUTHENTICATION_OPEN = 'SET_IS_AUTHENTICATION_OPEN',
2528
SET_IS_LOGIN_LOADING = 'SET_IS_LOGIN_LOADING',
29+
OPEN_STORY_MODE_MODAL = 'OPEN_STORY_MODE_MODAL',
30+
CLOSE_STORY_MODE_MODAL = 'CLOSE_STORY_MODE_MODAL',
2631
}
2732

2833
export const activateUser = (authToken: string, userId: number) =>
@@ -65,6 +70,14 @@ export namespace UserActions {
6570

6671
export const getUserDetails = () => action(Type.GET_USER_DETAILS);
6772

73+
export const getQuestStatus = () => action(Type.GET_USER_QUESTSTATUS);
74+
75+
export const updateQuestStatus = (ratings: object) =>
76+
action(Type.UPDATE_USER_QUESTSTATUS, { ratings });
77+
78+
export const setCurrentLevel = (level: number, stars: number) =>
79+
action(Type.SET_CURRENT_LEVEL, { level, stars });
80+
6881
export const editUserProfile = (editUserDetails: UserInterfaces.EditUserDetails) =>
6982
action(Type.EDIT_USER_PROFILE, { editUserDetails });
7083

@@ -98,4 +111,9 @@ export namespace UserActions {
98111

99112
export const setIsLoginLoading = (isLoginLoading: boolean) =>
100113
action(Type.SET_IS_LOGIN_LOADING, { isLoginLoading });
114+
115+
export const openStoryModeModal = (level: number) =>
116+
action(Type.OPEN_STORY_MODE_MODAL, { level });
117+
118+
export const closeStoryModeModal = () => action(Type.CLOSE_STORY_MODE_MODAL);
101119
}

src/app/apiFetch/User.ts

+17
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,20 @@ export const checkUsernameExists = (username: string) => {
180180
console.error(error);
181181
});
182182
};
183+
184+
export const userGetQuestStatus = () => {
185+
console.log('Inside apiFetch');
186+
return fetch(`${API_BASE_URL}user/quest-status`, {
187+
credentials: 'include',
188+
method: 'GET',
189+
})
190+
.then((response) => {
191+
return jsonResponseWrapper(response);
192+
})
193+
.then((data) => {
194+
return data;
195+
})
196+
.catch((error) => {
197+
console.error(error);
198+
});
199+
};

src/app/components/GameLog.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ export class GameLog extends React.Component<GameLogInterfaces.Props, {}> {
4040

4141
return (
4242
<AceEditor
43+
style={{
44+
zIndex: 0,
45+
}}
4346
ref={this.editorRef}
4447
cursorStart={20}
4548
mode="c_cpp"

src/app/components/Notification/index.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import * as NotificationInterfaces from 'app/types/Notification';
66
import classnames from 'classnames';
77
import * as React from 'react';
88
import { Col, Grid, Row } from 'react-bootstrap';
9-
// tslint:disable-next-line
10-
import ReactPaginate from 'react-paginate';
119

1210
// tslint:disable-next-line
13-
11+
import ReactPaginate from 'react-paginate';
1412
export class Notification extends React.Component<
1513
NotificationInterfaces.Props,
1614
NotificationInterfaces.State

src/app/components/StoryModeModal.tsx

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { faArrowRight, faStar, faTimes } from '@fortawesome/free-solid-svg-icons';
2+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
3+
import * as StoryModalPropType from 'app/types/StoryModeModal';
4+
import * as React from 'react';
5+
import { Button, Modal } from 'react-bootstrap';
6+
//
7+
8+
export class StoryModeModal extends React.Component<StoryModalPropType.Props, {}> {
9+
public render() {
10+
return (
11+
<Modal.Dialog
12+
style={{
13+
marginTop: '10%',
14+
zIndex: 10,
15+
}}
16+
>
17+
<Modal.Header>
18+
<Modal.Title>
19+
<div style={{ margin: 0 }}>
20+
<b>Level {this.props.level} !! </b>
21+
{[...Array(this.props.stars >= 0 ? this.props.stars : 0)].map(() => (
22+
<FontAwesomeIcon icon={faStar} style={{ color: 'gold' }} />
23+
))}
24+
</div>
25+
</Modal.Title>
26+
<button
27+
style={{ border: 0, padding: 0, margin: 0, backgroundColor: 'white' }}
28+
onClick={() => this.props.closeStoryModeModal()}
29+
>
30+
<FontAwesomeIcon icon={faTimes} style={{ float: 'right', cursor: 'pointer' }} />
31+
</button>
32+
</Modal.Header>
33+
<Modal.Body>{this.props.description}</Modal.Body>
34+
<Modal.Footer>
35+
<Button
36+
className={this.props.isCompleted ? 'btn-success' : 'btn-primary'}
37+
onClick={() => this.props.startMatch(1, this.props.level)}
38+
>
39+
{this.props.isCompleted ? 'Retry' : 'Start'} &nbsp;
40+
<FontAwesomeIcon icon={faArrowRight} />
41+
</Button>
42+
</Modal.Footer>
43+
</Modal.Dialog>
44+
);
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { faStar } from '@fortawesome/free-solid-svg-icons';
2+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
3+
import * as styles from 'app/styles/DeltaStarCount.module.css';
4+
import * as DeltaStarCountInterfaces from 'app/types/DeltaStarCount';
5+
6+
import classnames from 'classnames';
7+
import * as React from 'react';
8+
9+
export class DeltaStarCount extends React.Component<DeltaStarCountInterfaces.Props, {}> {
10+
constructor(props: DeltaStarCountInterfaces.Props) {
11+
super(props);
12+
}
13+
14+
public render() {
15+
return <span className={classnames(styles.starSpan)}>{this.mapStars()}</span>;
16+
}
17+
18+
private whiteStars() {
19+
const { rating } = this.props;
20+
const maxRating = 3;
21+
return maxRating - rating;
22+
}
23+
24+
private mapStars() {
25+
const starsArray = [1, 1, 1];
26+
for (let index = 1; index <= this.whiteStars(); index += 1) starsArray[index - 1] = 0;
27+
const stars = starsArray.map((starValue) => this.starImage(starValue));
28+
return stars;
29+
}
30+
31+
private starImage(value: number) {
32+
return value ? (
33+
<FontAwesomeIcon
34+
className={classnames(styles.star)}
35+
icon={faStar}
36+
style={{ color: 'gold' }}
37+
/>
38+
) : (
39+
<FontAwesomeIcon
40+
className={classnames(styles.star)}
41+
icon={faStar}
42+
style={{ color: 'gray' }}
43+
/>
44+
);
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { DeltaStarCount } from 'app/components/SubmitBar/DeltaStarCount';
2+
import * as styles from 'app/styles/SubmitBar.module.css';
3+
import * as DropDownItemInterfaces from 'app/types/DropDownItem';
4+
import * as React from 'react';
5+
6+
import { Tooltip } from '@material-ui/core';
7+
8+
export class DropDownItem extends React.Component<DropDownItemInterfaces.Props, {}> {
9+
constructor(props: DropDownItemInterfaces.Props) {
10+
super(props);
11+
}
12+
13+
public render() {
14+
const { level, rating, openStoryModeModal, setCurrentLevel } = this.props;
15+
return (
16+
<span>
17+
{rating !== -1 || Number(level) === 1 ? (
18+
<div
19+
onClick={(e) => {
20+
setCurrentLevel(Number(level), rating);
21+
openStoryModeModal(Number(level));
22+
}}
23+
>
24+
<span>LVL {level}</span>
25+
<DeltaStarCount rating={rating} />
26+
</div>
27+
) : (
28+
<Tooltip title={'Unlock the previous level'} placement={'right'}>
29+
<div style={{ opacity: 0.2 }}>
30+
<span className={styles['dropdown-content-LVL']}>LVL {level}</span>
31+
<DeltaStarCount rating={0} />
32+
</div>
33+
</Tooltip>
34+
)}
35+
</span>
36+
);
37+
}
38+
}

0 commit comments

Comments
 (0)