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

View File

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

View File

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

View File

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

View File

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

View File

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