File size: 995 Bytes
597ee18 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import React, { Component, PropTypes } from 'react';
class PatchCounter extends Component {
getUniqueAuthors(patches){
return patches.reduce(function(prev, curr) {
if(!curr.author){
return prev;
}
const author = curr.author.wordpressId || curr.author.name;
if(prev.indexOf(author) === -1){
prev.push(author);
}
return prev;
}, []);
}
render(){
const { patches, myPatches } = this.props;
const numAuthors = this.getUniqueAuthors(patches).length;
const numPatches = patches.length;
return (
<div id="patch-counter">
<div>
<span>{numPatches} {myPatches ? null : 'public'} { numPatches === 1 ? 'patch' : 'patches' }</span>
{ myPatches ? null : (<span> by {numAuthors} { numAuthors === 1 ? 'author.' : 'authors.' } </span>) }
</div>
</div>
);
}
}
PatchCounter.proptypes = {
patches: PropTypes.array,
myPatches: PropTypes.bool
}
export default PatchCounter;
|