Skip to content

Commit f2ce679

Browse files
committed
fixup! Change the Route for profile user stats
1 parent 41edbf3 commit f2ce679

File tree

11 files changed

+117
-14
lines changed

11 files changed

+117
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"predeploy": "npm run build",
99
"test": "jest -i",
10-
"start": "webpack-dev-server --mode development --hot --progress --color --port 3000",
10+
"start": "webpack-dev-server --mode development --hot --progress --color --port 3000 --host 0.0.0.0",
1111
"build": "webpack -p --progress --colors",
1212
"lint": "prettier --write \"src/**/*.{ts,tsx,css}\" \"__tests__/**/*.{ts,tsx,css}\" && tslint --project .",
1313
"lint:fix": "tslint --project . --fix"

src/app/actions/ProfileUser.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
import * as ProfileUserInterfaces from 'app/types/User';
1+
import * as ProfileInterfaces from 'app/types/ProfileUser';
2+
import * as UserInterfaces from 'app/types/User';
23
import { action } from 'typesafe-actions';
34

45
export namespace ProfileUserActions {
56
export enum Type {
67
GET_PROFILE_USER_DETAILS = 'GET_USER_DETAILS',
78
GET_MATCH_STATS = 'GET_MATCH_STATS',
89
UPDATE_PROFILE_USER_DETAILS = 'UPDATE_PROFILE_USER_DETAILS',
10+
UPDATE_MATCH_STATS = 'UPDATE_MATCH_STATS',
911
}
1012

1113
interface ProfileUserDetails {
1214
avatar?: string;
1315
college?: string;
14-
userType?: ProfileUserInterfaces.UserType;
16+
userType?: UserInterfaces.UserType;
1517
fullName?: string;
1618
username?: string;
1719
email?: string;
@@ -21,7 +23,11 @@ export namespace ProfileUserActions {
2123
export const updateProfileUserDetails = (profileuserDetails: ProfileUserDetails) =>
2224
action(Type.UPDATE_PROFILE_USER_DETAILS, { profileuserDetails });
2325

24-
export const getUserDetails = () => action(Type.GET_PROFILE_USER_DETAILS);
26+
export const getUserDetails = (username: string) =>
27+
action(Type.GET_PROFILE_USER_DETAILS, { username });
28+
29+
export const updateMatchStats = (matchStats: ProfileInterfaces.ProfileMatchStats) =>
30+
action(Type.UPDATE_MATCH_STATS, { matchStats });
2531

2632
export const getMatchStats = (username: string) => action(Type.GET_MATCH_STATS, { username });
2733
}

src/app/apiFetch/ProfileUser.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,34 @@ export const getMatchStats = (username: string) => {
99
method: 'GET',
1010
})
1111
.then((response) => {
12+
console.log('fetch match response');
13+
console.log(response);
1214
return jsonResponseWrapper(response);
1315
})
1416
.then((data) => {
17+
console.log('fetch match data');
18+
console.log(data);
19+
return data;
20+
})
21+
.catch((error) => {
22+
console.error(error);
23+
});
24+
};
25+
26+
export const getUserProfile = (username: string) => {
27+
const URL = `${API_BASE_URL}user/${username}`;
28+
return fetch(URL, {
29+
credentials: 'include',
30+
method: 'GET',
31+
})
32+
.then((response) => {
33+
console.log('fetch profile response');
34+
console.log(response);
35+
return jsonResponseWrapper(response);
36+
})
37+
.then((data) => {
38+
console.log('fetch profile data');
39+
console.log(data);
1540
return data;
1641
})
1742
.catch((error) => {
Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1+
import { Avatar } from 'app/types/Authentication/Register';
12
import * as ProfileUserInterface from 'app/types/ProfileUser';
23
import * as React from 'react';
34

45
export default class ProfileUserStats extends React.Component<ProfileUserInterface.Props, {}> {
6+
public componentDidMount() {
7+
this.props.getUserDetails('');
8+
this.props.getMatchStats(this.props.match.params.username);
9+
}
510
public render() {
6-
console.log(this.props.match.params.username);
7-
return <p>This is the Page for Profile user stats</p>;
8-
}
11+
// console.log(this.props.profileUserDetails);
12+
return (
13+
<div>
14+
{
15+
// @ts-ignore
16+
<img src={Avatar[this.props.profileUserDetails.avatar]} />
17+
}
18+
</div>
19+
);
20+
}
921
}

src/app/components/UserProfileModal/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import PopUpMenu from 'app/components/PopUpMenu';
1+
import { faChartLine, faLock, faUser } from '@fortawesome/free-solid-svg-icons';
22
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
3-
import { faChartLine, faUser, faLock } from '@fortawesome/free-solid-svg-icons';
3+
import PopUpMenu from 'app/components/PopUpMenu';
44
import { EditPassword } from 'app/components/UserProfileModal/EditPassword';
55
import { EditProfile } from 'app/components/UserProfileModal/EditProfile';
66
import { UserStats } from 'app/components/UserProfileModal/UserStats';

src/app/containers/ProfileUsersStats.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const mapStateToProps = (rootState: RootState) => {
1414
const mapDispatchToProps = (dispatch: Dispatch) => {
1515
return {
1616
getMatchStats: (username: string) => dispatch(ProfileUserActions.getMatchStats(username)),
17-
getUserDetails: () => dispatch(ProfileUserActions.getUserDetails()),
17+
getUserDetails: (username: string) => dispatch(ProfileUserActions.getUserDetails(username)),
1818
updateProfileUserDetails: (
1919
updateProfileUserDetails: ProfileUserInterfaces.EditProfileUserDetails,
2020
) => dispatch(ProfileUserActions.updateProfileUserDetails(updateProfileUserDetails)),

src/app/reducers/ProfileUser.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ const profileStoreIntialState: ProfileUserInterfaces.ProfileUserStoreState = {
77
country: 'IN',
88
email: '',
99
fullName: '',
10+
matchStats: {
11+
auto: { wins: 0, losses: 0, ties: 0 },
12+
faced: { wins: 0, losses: 0, ties: 0 },
13+
initiated: { wins: 0, losses: 0, ties: 0 },
14+
lastMatchAt: '',
15+
numMatchches: 0,
16+
userId: 0,
17+
},
1018
type: '',
1119
userType: ProfileUserInterfaces.ProfileUserType.STUDENT,
1220
username: '',
@@ -40,6 +48,13 @@ export const profileuserReducer = (
4048
};
4149
}
4250

51+
case ProfileUserActions.Type.UPDATE_MATCH_STATS: {
52+
return {
53+
...state,
54+
matchStats: action.payload.matchStats,
55+
};
56+
}
57+
4358
default:
4459
return state;
4560
}

src/app/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ export enum Routes {
77
GITHUB_OAUTH = '/login/github',
88
GOOGLE_OAUTH = '/login/google',
99
USER_ACTIVATION = '/user-activate',
10-
PROFILE_USER_STATS = '/:username',
10+
PROFILE_USER_STATS = '/profile::username',
1111
}

src/app/sagas/ProfileUser.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { ProfileUserActions, UserActions } from 'app/actions';
33
import * as ProfileUserFetch from 'app/apiFetch/ProfileUser';
44
import { avatarName } from 'app/types/Authentication/Register';
55
import { resType } from 'app/types/sagas';
6-
import { call, put } from 'redux-saga/effects';
6+
import { all, call, put, takeEvery } from 'redux-saga/effects';
77
import { ActionType } from 'typesafe-actions';
88

99
export function* getMatchStats(action: ActionType<typeof ProfileUserActions.getMatchStats>) {
1010
try {
1111
const res = yield call(ProfileUserFetch.getMatchStats, action.payload.username);
1212
yield put(UserActions.updateErrorMessage(res.error));
13+
console.log('saga match res');
14+
console.log(res);
1315
if (res.type !== resType.ERROR) {
1416
const { avatarId, college, country, fullName, userType, username } = res.body;
1517
yield put(
@@ -27,3 +29,20 @@ export function* getMatchStats(action: ActionType<typeof ProfileUserActions.getM
2729
console.error(err);
2830
}
2931
}
32+
33+
export function* getUserProfile(action: ActionType<typeof ProfileUserActions.getUserDetails>) {
34+
try {
35+
const res = yield call(ProfileUserFetch.getUserProfile, action.payload.username);
36+
console.log('saga profile res');
37+
console.log(res);
38+
} catch (err) {
39+
console.error(err);
40+
}
41+
}
42+
43+
export function* profileSagas() {
44+
yield all([
45+
takeEvery(ProfileUserActions.Type.GET_MATCH_STATS, getMatchStats),
46+
takeEvery(ProfileUserActions.Type.GET_PROFILE_USER_DETAILS, getUserProfile),
47+
]);
48+
}

src/app/store/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { codeSagas } from 'app/sagas/Code';
44
import { leaderboardSagas } from 'app/sagas/Leaderboard';
55
import { matchSagas } from 'app/sagas/MatchView';
66
import { notificationSagas } from 'app/sagas/Notification';
7+
import { profileSagas } from 'app/sagas/ProfileUser';
78
import { submissionSagas } from 'app/sagas/Submission';
89
import { userSagas } from 'app/sagas/User';
910
import { applyMiddleware, createStore } from 'redux';
@@ -32,6 +33,7 @@ export function configureStore(initialState?: object) {
3233
const store = createStore(persistedReducer, initialState, middleware);
3334
sagaMiddleware.run(userSagas);
3435
sagaMiddleware.run(codeSagas);
36+
sagaMiddleware.run(profileSagas);
3537
sagaMiddleware.run(leaderboardSagas);
3638
sagaMiddleware.run(submissionSagas);
3739
sagaMiddleware.run(matchSagas);

0 commit comments

Comments
 (0)