Skip to content

Commit c827fdd

Browse files
committed
Add route for /profile/:user and Add the required container
1 parent 70d9e86 commit c827fdd

File tree

12 files changed

+84
-20
lines changed

12 files changed

+84
-20
lines changed

src/app/actions/ProfileUser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export namespace ProfileUserActions {
1818
country?: string;
1919
}
2020

21-
export const updateUserDetails = (profileuserDetails: ProfileUserDetails) =>
21+
export const updateProfileUserDetails = (profileuserDetails: ProfileUserDetails) =>
2222
action(Type.UPDATE_PROFILE_USER_DETAILS, { profileuserDetails });
2323

2424
export const getUserDetails = () => action(Type.GET_PROFILE_USER_DETAILS);

src/app/apiFetch/ProfileUser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { jsonResponseWrapper } from 'app/apiFetch/utils';
33
import { API_BASE_URL } from '../../config/config';
44

55
export const getMatchStats = (username: string) => {
6-
const URL = `${API_BASE_URL}/match-stats/${encodeURIComponent(username)}`;
6+
const URL = `${API_BASE_URL}user/match-stats/${encodeURIComponent(username)}`;
77
return fetch(URL, {
88
credentials: 'include',
99
method: 'GET',

src/app/components/Leaderboard/LeaderboardElement.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ const colors = ['#FFB900', '#69797E', '#847545', '#038387'];
1616
export class LeaderboardElement extends React.Component<LeaderboardInterfaces.ElementProps, {}> {
1717
public render() {
1818
const { player, index, isPlayAgainstDisabled, runMatch, currentUsername } = this.props;
19-
19+
if (player.username === currentUsername) {
20+
const urlToProfile = `/profile`;
21+
} else {
22+
const urlToProfile = `/profile/${player.username}`;
23+
}
2024
const playerTotalMatches = player.numWin + player.numLoss + player.numTie;
2125

2226
return (
@@ -86,9 +90,11 @@ export class LeaderboardElement extends React.Component<LeaderboardInterfaces.El
8690
}}
8791
title={player.username}
8892
>
89-
<span>{`${player.username.substr(0, 15)}${
90-
player.username.length > 15 ? '...' : ''
91-
}`}</span>
93+
<a href={urlToProfile}>
94+
<span>{`${player.username.substr(0, 15)}${
95+
player.username.length > 15 ? '...' : ''
96+
}`}</span>
97+
</a>
9298
</div>
9399
<div
94100
className={classnames(styles['leader-score_title'])}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as ProfileUserInterface from 'app/types/ProfileUser';
2+
import * as React from 'react';
3+
4+
export class ProfileUserStats extends React.Component<ProfileUserInterface.Props, {}> {
5+
public render() {
6+
return <p>This is the Page for Profile user stats</p>;
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as React from 'react';
2+
3+
export class UserStats extends React.Component {
4+
public render() {
5+
return <p>This is the Page for Current user stats</p>;
6+
}
7+
}

src/app/components/UserProfileModal/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { faChartLine, faLock, faUser } from '@fortawesome/free-solid-svg-icons';
22
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
33
import { EditPassword } from 'app/components/UserProfileModal/EditPassword';
44
import { EditProfile } from 'app/components/UserProfileModal/EditProfile';
5+
import { UserStats } from 'app/components/UserProfileModal/UserStats';
56
import * as styles from 'app/styles/UserProfileModal.module.css';
67
import * as UserProfileInterfaces from 'app/types/UserProfileModal';
78
import classnames from 'classnames';
@@ -78,8 +79,12 @@ export class UserProfileModal extends React.Component<
7879
);
7980
break;
8081

82+
case UserProfileInterfaces.SelectedPage.USERSTATS:
83+
return <UserStats />;
84+
break;
85+
8186
default:
82-
return <p>Hello World</p>;
87+
return <p>Default</p>;
8388
}
8489
}
8590

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { ProfileUserActions } from 'app/actions';
2+
import { ProfileUserStats } from 'app/components/ProfileUserStats';
3+
import { RootState } from 'app/reducers';
4+
import * as ProfileUserInterfaces from 'app/types/ProfileUser';
5+
import { connect } from 'react-redux';
6+
import { Dispatch } from 'redux';
7+
8+
const mapStateToProps = (rootState: RootState) => {
9+
return {
10+
profileUserDetails: rootState.profileUser,
11+
};
12+
};
13+
14+
const mapDispatchToProps = (dispatch: Dispatch) => {
15+
return {
16+
getMatchStats: (username: string) => dispatch(ProfileUserActions.getMatchStats(username)),
17+
getUserDetails: () => dispatch(ProfileUserActions.getUserDetails()),
18+
updateProfileUserDetails: (
19+
updateProfileUserDetails: ProfileUserInterfaces.EditProfileUserDetails,
20+
) => dispatch(ProfileUserActions.updateProfileUserDetails(updateProfileUserDetails)),
21+
};
22+
};
23+
24+
const profileUserContainer = connect<
25+
ProfileUserInterfaces.StateProps,
26+
ProfileUserInterfaces.DispatchProps,
27+
{}
28+
>(
29+
mapStateToProps,
30+
mapDispatchToProps,
31+
)(ProfileUserStats);
32+
33+
export default profileUserContainer;

src/app/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Register from 'app/containers/Authentication/Register';
44
import Dashboard from 'app/containers/Dashboard';
55
import Leaderboard from 'app/containers/Leaderboard';
66
import UserProfileModal from 'app/containers/UserProfileModal';
7+
import profileUserContainer from 'app/containers/ProfileUsersStats'
78
import { Routes } from 'app/routes';
89
// @ts-ignore
910
import { initializeRendererAssets } from 'codecharacter-renderer';
@@ -24,6 +25,7 @@ export const App = hot(module)(() => (
2425
<Route exact path={Routes.REGISTER} component={Register} />
2526
<Route exact path={Routes.LEADERBOARD} component={Leaderboard} />
2627
<Route exact path={Routes.USER_PROFILE_MODEL} component={UserProfileModal} />
28+
<Route exact path={Routes.PROFILE_USER_STATS} component={profileUserContainer} />
2729
</Switch>
2830
<PopUpMenu />
2931
<Sugar background="#484848" color="white" />

src/app/reducers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ export interface RootState {
4545
router: RouterState;
4646
gameLog: GameLogInterfaces.GameLogStoreState;
4747
user: UserInterfaces.UserStoreState;
48-
profileuser: ProfileUserInterfaces.ProfileUserStoreState;
48+
profileUser: ProfileUserInterfaces.ProfileUserStoreState;
4949
submission: SubmissionInterfaces.SubmissionStoreState;
5050
}

src/app/routes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export enum Routes {
44
REGISTER = '/register',
55
LEADERBOARD = '/leaderboard',
66
USER_PROFILE_MODEL = '/profile',
7+
PROFILE_USER_STATS = '/profile/:username',
78
}

0 commit comments

Comments
 (0)