diff --git a/app/assets/javascripts/discourse/widgets/post-gutter.js.es6 b/app/assets/javascripts/discourse/widgets/post-gutter.js.es6 index f580b9aea53..61d7f973e0f 100644 --- a/app/assets/javascripts/discourse/widgets/post-gutter.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post-gutter.js.es6 @@ -21,30 +21,27 @@ export default createWidget('post-gutter', { const seenTitles = {}; - - let i = 0; - while (i < links.length && result.length < toShow) { - const l = links[i++]; - + let titleCount = 0; + links.forEach(function(l) { let title = l.title; if (title && !seenTitles[title]) { seenTitles[title] = true; - const linkBody = [new RawHtml({ html: `${Discourse.Emoji.unescape(title)}` })]; - if (l.clicks) { - linkBody.push(h('span.badge.badge-notification.clicks', l.clicks.toString())); - } + titleCount++; + if (result.length < toShow) { + const linkBody = [new RawHtml({html: `${Discourse.Emoji.unescape(title)}`})]; + if (l.clicks) { + linkBody.push(h('span.badge.badge-notification.clicks', l.clicks.toString())); + } - const className = l.reflection ? 'inbound' : 'outbound'; - const link = h('a.track-link', { className, attributes: { href: l.url } }, linkBody); - result.push(h('li', link)); + const className = l.reflection ? 'inbound' : 'outbound'; + const link = h('a.track-link', {className, attributes: {href: l.url}}, linkBody); + result.push(h('li', link)); + } } - } + }); if (state.collapsed) { - var differentTitles = [], allTitles = []; - links.forEach(function(x) { allTitles.push(x.title); }); - differentTitles = allTitles.filter(function(item, iter, ar){ return ar.indexOf(item) === iter; }); - const remaining = differentTitles.length - MAX_GUTTER_LINKS; + const remaining = titleCount - MAX_GUTTER_LINKS; if (remaining > 0) { result.push(h('li', h('a.toggle-more', I18n.t('post.more_links', {count: remaining}))));