feat(profile): Create top contributor badge (#17805)

This commit is contained in:
Buğra Gündüz
2018-08-02 18:39:51 +03:00
committed by mrugesh mohapatra
parent d7180d8a4f
commit 3c72c93a8d
6 changed files with 43 additions and 9 deletions

View File

@ -14,14 +14,16 @@ const mapStateToProps = createSelector(
location,
points,
picture,
about
about,
yearsTopContributor
}) => ({
name,
username,
location,
points,
picture,
about
about,
yearsTopContributor
})
);
@ -35,7 +37,8 @@ const propTypes = {
showLocation: PropTypes.bool,
showName: PropTypes.bool,
showPoints: PropTypes.bool,
username: PropTypes.string
username: PropTypes.string,
yearsTopContributor: PropTypes.array
};
function CamperHOC({
@ -45,6 +48,7 @@ function CamperHOC({
points,
picture,
about,
yearsTopContributor,
showAbout,
showLocation,
showName,
@ -60,6 +64,7 @@ function CamperHOC({
picture={ picture }
points={ showPoints ? points : null }
username={ username }
yearsTopContributor={ yearsTopContributor }
/>
<hr />
</div>

View File

@ -21,7 +21,7 @@
text-align: center;
}
.name, .location, .bio, .points {
.name, .location, .bio, .points, .yearsTopContributor {
font-size: 2rem;
margin-bottom: 0;
}

View File

@ -10,12 +10,26 @@ const propTypes = {
name: PropTypes.string,
picture: PropTypes.string,
points: PropTypes.number,
username: PropTypes.string
username: PropTypes.string,
yearsTopContributor: PropTypes.array
};
function pluralise(word, condition) {
return condition ? word + 's' : word;
}
function joinArray(array) {
return array.reduce((string, item, index, array) => {
if (string.length > 0) {
if (index === array.length - 1) {
return `${string} and ${item}`;
} else {
return `${string}, ${item}`;
}
} else {
return item;
}
});
}
function Camper({
name,
@ -23,7 +37,8 @@ function Camper({
location,
points,
picture,
about
about,
yearsTopContributor
}) {
return (
@ -49,6 +64,13 @@ function Camper({
</p>
) : null
}
{ yearsTopContributor.length > 0 &&
(
<p className='text-center yearsTopContributor'>
Top Contributor of { joinArray(yearsTopContributor) }
</p>
)
}
<br/>
</div>
);

View File

@ -850,7 +850,8 @@ module.exports = function(User) {
points,
portfolio,
streak,
username
username,
yearsTopContributor
} = user;
const {
isLocked = true,
@ -881,7 +882,8 @@ module.exports = function(User) {
name: showName ? name : '',
points: showPoints ? points : null,
portfolio: showPortfolio ? portfolio : [],
streak: showHeatMap ? streak : {}
streak: showHeatMap ? streak : {},
yearsTopContributor: yearsTopContributor
};
}

View File

@ -206,6 +206,10 @@
"type": "array",
"default": []
},
"yearsTopContributor": {
"type": "array",
"default": []
},
"rand": {
"type": "number",
"index": true

View File

@ -35,7 +35,8 @@ export const publicUserProps = [
'streak',
'twitter',
'username',
'website'
'website',
'yearsTopContributor'
];
export const userPropsForSession = [