Refactor renderNameList (thanks, @richvdh)

This commit is contained in:
Luke Barnard 2016-11-10 17:36:22 +00:00
parent 0695037f5f
commit 3d7f6919cf

View file

@ -75,20 +75,20 @@ module.exports = React.createClass({
return this._getEventSenderName(lastEvent); return this._getEventSenderName(lastEvent);
} }
// Special case the last name. ' and ' might be included later let lastName = this._getEventSenderName(lastEvent);
// So you have two cases: if (names.length === 0) {
if (originalNumber <= this.props.summaryLength) { // special-case for a single event
// name1, name2 and name3 return lastName;
names += ' and ';
} else {
// name1, name2, name3 [and 100 others]
names += ', ';
} }
let remaining = originalNumber - this.props.summaryLength; let remaining = originalNumber - this.props.summaryLength;
let remainingDesc = (remaining > 0 ? ' and ' + remaining + ' others ':''); if (remaining > 0) {
// name1, name2, name3, and 100 others
return names + this._getEventSenderName(lastEvent) + remainingDesc; return names + ', ' + lastName + ', and ' + remaining + ' others';
} else {
// name1, name2 and name3
return names + ' and ' + lastName;
}
}, },
_renderSummary: function(joinEvents, leaveEvents) { _renderSummary: function(joinEvents, leaveEvents) {