Skip to content

Commit

Permalink
feature: profile page show no rating mm entrance
Browse files Browse the repository at this point in the history
  • Loading branch information
yoution committed May 25, 2022
1 parent a2f6055 commit ed87edd
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ exports[`renders a full Profile correctly 1`] = `
<ProfileHeader
copilot={true}
country=""
hasMM={null}
info={
Object {
"competitionCountryCode": "USA",
Expand Down Expand Up @@ -198,6 +199,7 @@ exports[`renders a full Profile correctly 1`] = `
<StatsCategory
className=""
handle="testHandle"
hasMM={null}
inModal={false}
stats={
Object {
Expand Down Expand Up @@ -644,6 +646,7 @@ exports[`renders an empty Profile correctly 1`] = `
<ProfileHeader
copilot={false}
country=""
hasMM={null}
info={
Object {
"competitionCountryCode": "USA",
Expand Down Expand Up @@ -698,6 +701,7 @@ exports[`renders an empty Profile correctly 1`] = `
<StatsCategory
className=""
handle="testHandle"
hasMM={null}
inModal={false}
stats={
Object {
Expand Down
7 changes: 5 additions & 2 deletions src/shared/components/ProfilePage/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import React from 'react';
import PT from 'prop-types';
import { noop, get } from 'lodash';
import { noop, get, indexOf } from 'lodash';
import moment from 'moment';
import ReactSVG from 'react-svg';

Expand Down Expand Up @@ -57,6 +57,7 @@ class ProfileHeader extends React.Component {
info,
onShowBadges,
showBadgesButton,
hasMM,
wins,
} = this.props;
const { imageUrl } = this.state;
Expand Down Expand Up @@ -94,7 +95,7 @@ class ProfileHeader extends React.Component {
<div styleName="tracks-links">
<div styleName="tracks">
{
[...info.tracks, ...(copilot ? ['COPILOT'] : [])].map(track => (
[...info.tracks, ...(indexOf(info.track, 'DATA_SCIENCE') === -1 && hasMM ? ['DATA_SCIENCE'] : []), ...(copilot ? ['COPILOT'] : [])].map(track => (
<a href={`#${track}`} key={track} styleName="track">
{ track === 'COPILOT' && <CopilotIcon styleName="track-icon" /> }
{ track === 'DATA_SCIENCE' && <DataScienceIcon styleName="track-icon" /> }
Expand Down Expand Up @@ -140,6 +141,7 @@ class ProfileHeader extends React.Component {

ProfileHeader.defaultProps = {
copilot: false,
hasMM: false,
country: '',
info: {},
onShowBadges: noop,
Expand All @@ -149,6 +151,7 @@ ProfileHeader.defaultProps = {

ProfileHeader.propTypes = {
copilot: PT.bool,
hasMM: PT.bool,
country: PT.string,
info: PT.shape(),
onShowBadges: PT.func,
Expand Down
10 changes: 7 additions & 3 deletions src/shared/components/ProfilePage/StatsCategory/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const isHidden = (subtrack) => {
class StatsCategory extends React.Component {
getActiveTracks() {
let { stats } = this.props;
const { hasMM } = this.props;
if (_.isArray(stats)) {
// eslint-disable-next-line prefer-destructuring
stats = stats[0];
Expand Down Expand Up @@ -87,7 +88,7 @@ class StatsCategory extends React.Component {
}

subTracks.forEach((subtrack) => {
if (isActiveSubtrack(subtrack) && !isHidden(subtrack)) {
if ((isActiveSubtrack(subtrack) && !isHidden(subtrack)) || (subtrack.name === 'MARATHON MATCH' && hasMM)) {
active.push({ ...subtrack, active: true });
}
});
Expand All @@ -106,6 +107,7 @@ class StatsCategory extends React.Component {
render() {
const {
handle,
hasMM,
className,
inModal,
} = this.props;
Expand Down Expand Up @@ -148,10 +150,10 @@ class StatsCategory extends React.Component {
style={{ color: getRatingColor(subtrack.rank.rating) }}
styleName="number"
>
{subtrack.rank.rating}
{subtrack.name === 'MARATHON MATCH' && !subtrack.challenges && hasMM ? '' : subtrack.rank.rating}
</div>
<div styleName="tag">
Rating
{subtrack.name === 'MARATHON MATCH' && !subtrack.challenges && hasMM ? 'No Rating' : 'Rating'}
</div>
</div>
)
Expand Down Expand Up @@ -198,6 +200,7 @@ class StatsCategory extends React.Component {
StatsCategory.defaultProps = {
className: '',
inModal: false,
hasMM: false,
};

StatsCategory.propTypes = {
Expand All @@ -207,6 +210,7 @@ StatsCategory.propTypes = {
PT.shape(),
]).isRequired,
inModal: PT.bool,
hasMM: PT.bool,
className: PT.string,
};

Expand Down
12 changes: 11 additions & 1 deletion src/shared/components/ProfilePage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class ProfilePage extends React.Component {
copilot,
externalAccounts,
externalLinks,
challenges,
skills: propSkills,
stats,
lookupData,
Expand Down Expand Up @@ -167,6 +168,8 @@ class ProfilePage extends React.Component {
}

const activeTracks = this.getActiveTracks();
// no rating MM
const hasMM = challenges && challenges.length;

return (
<div styleName="outer-container">
Expand All @@ -192,6 +195,7 @@ class ProfilePage extends React.Component {
>
<div styleName="sticky-container">
<Header
hasMM={hasMM}
copilot={copilot}
country={country}
info={info}
Expand Down Expand Up @@ -272,7 +276,11 @@ class ProfilePage extends React.Component {
{
!_.isEmpty(stats) && (
<div id="profile-activity">
<StatsCategory handle={info.handle} stats={stats} />
<StatsCategory
handle={info.handle}
stats={stats}
hasMM={hasMM}
/>
</div>
)
}
Expand Down Expand Up @@ -310,6 +318,7 @@ ProfilePage.defaultProps = {
externalAccounts: null,
externalLinks: null,
achievements: [],
challenges: null,
skills: null,
stats: null,
};
Expand All @@ -318,6 +327,7 @@ ProfilePage.propTypes = {
achievements: PT.arrayOf(PT.shape()),
copilot: PT.bool.isRequired,
externalAccounts: PT.shape(),
challenges: PT.arrayOf(PT.shape()),
externalLinks: PT.arrayOf(PT.shape()),
info: PT.shape().isRequired,
skills: PT.shape(),
Expand Down
30 changes: 30 additions & 0 deletions src/shared/containers/Profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,31 @@ import PT from 'prop-types';
import { connect } from 'react-redux';
import { config } from 'topcoder-react-utils';
import { actions } from 'topcoder-react-lib';
import shortId from 'shortid';
import MetaTags from 'components/MetaTags';
import Error404 from 'components/Error404';
import LoadingIndicator from 'components/LoadingIndicator';
import ProfilePage from 'components/ProfilePage';
import { loadPublicStatsOnly } from 'utils/memberStats';

// how many challenges to query per batch
const CHALLENGE_PER_PAGE = 36;

class ProfileContainer extends React.Component {
componentDidMount() {
const {
handleParam,
loadProfile,
loadMarathon,
meta,
auth,
info,
} = this.props;
loadProfile(handleParam, _.get(meta, 'groupIds', []), auth.tokenV3, loadPublicStatsOnly(meta));

if (info) {
loadMarathon(handleParam, auth.tokenV3, info.userId);
}
// Redirect to the communities own profile page if
// - the member whose profile is being viewed is part of one of the configured communities
// - the user is not a topcoder user (has an email with @topcoder.com)
Expand Down Expand Up @@ -53,6 +62,7 @@ class ProfileContainer extends React.Component {
handleParam,
profileForHandle,
loadProfile,
loadMarathon,
loadMemberGroups,
meta,
auth,
Expand All @@ -69,6 +79,9 @@ class ProfileContainer extends React.Component {
loadProfile(handleParam, _.get(meta, 'groupIds', []), auth.tokenV3, loadPublicStatsOnly(meta));
}

if (info && info.userId && info !== prevInfo) {
loadMarathon(handleParam, auth.tokenV3, info.userId);
}
if (auth.tokenV3 && auth.user && auth.user.handle !== handleParam
&& info != null && info.userId != null
&& (prevInfo == null || info.userId !== prevInfo.userId)) {
Expand Down Expand Up @@ -158,6 +171,7 @@ ProfileContainer.propTypes = {
handleParam: PT.string.isRequired,
info: PT.shape(),
loadingError: PT.bool.isRequired,
loadMarathon: PT.bool.isRequired,
loadProfile: PT.func.isRequired,
loadMemberGroups: PT.func.isRequired,
profileForHandle: PT.string,
Expand All @@ -170,6 +184,8 @@ ProfileContainer.propTypes = {
};

const mapStateToProps = (state, ownProps) => ({
challenges: state.members[ownProps.match.params.handle]
? state.members[ownProps.match.params.handle].subtrackChallenges : null,
achievements: state.profile.achievements,
copilot: state.profile.copilot,
country: state.profile.country,
Expand All @@ -192,6 +208,7 @@ const mapStateToProps = (state, ownProps) => ({
function mapDispatchToProps(dispatch) {
const a = actions.profile;
const lookupActions = actions.lookup;
const memberActions = actions.members;
return {
loadMemberGroups: (userId, tokenV3) => {
dispatch(actions.groups.getMemberGroups(userId, tokenV3));
Expand All @@ -214,6 +231,19 @@ function mapDispatchToProps(dispatch) {
dispatch(a.getStatsDone(handle, showPublicStats ? undefined : groupIds, tokenV3));
dispatch(lookupActions.getCountriesDone());
},
loadMarathon: (handle, tokenV3, memberId) => {
const uuid = shortId();
dispatch(memberActions.getUserMarathonInit(handle, uuid));
dispatch(memberActions.getUserMarathonDone(
uuid,
handle,
memberId,
tokenV3,
1,
CHALLENGE_PER_PAGE,
true,
));
},
};
}

Expand Down

0 comments on commit ed87edd

Please sign in to comment.