Factor out "and others"

This commit is contained in:
Luke Barnard 2016-11-10 14:33:41 +00:00
parent d6b74becfc
commit 6b2aa43b71

View file

@ -85,19 +85,22 @@ module.exports = React.createClass({
// name1, name2, name3 [and 100 others] // name1, name2, name3 [and 100 others]
names += ', '; names += ', ';
} }
return names + this._getEventSenderName(lastEvent);
let remaining = originalNumber - this.props.summaryLength;
let remainingDesc = (remaining > 0 ? 'and ' + remaining + ' others ':'');
return names + this._getEventSenderName(lastEvent) + remainingDesc;
}, },
_renderSummary: function(joinEvents, leaveEvents) { _renderSummary: function(joinEvents, leaveEvents) {
let joiners = this._renderNameList(joinEvents); let joiners = this._renderNameList(joinEvents);
let remainingJoiners = joinEvents.length - this.props.summaryLength;
let leavers = this._renderNameList(leaveEvents); let leavers = this._renderNameList(leaveEvents);
let remainingLeavers = leaveEvents.length - this.props.summaryLength;
let joinSummary = null; let joinSummary = null;
if (joiners) { if (joiners) {
joinSummary = ( joinSummary = (
<span> <span>
{joiners} {remainingJoiners > 0 ? 'and ' + remainingJoiners + ' others ':''}joined the room {joiners} joined the room
</span> </span>
); );
} }
@ -105,7 +108,7 @@ module.exports = React.createClass({
if (leavers) { if (leavers) {
leaveSummary = ( leaveSummary = (
<span> <span>
{leavers} {remainingLeavers > 0 ? 'and ' + remainingLeavers + ' others ':''}left the room {leavers} left the room
</span> </span>
); );
} }