const MAX_SHOWN = 5; import StringBuffer from 'discourse/mixins/string-buffer'; import { iconHTML } from 'discourse/helpers/fa-icon'; import computed from 'ember-addons/ember-computed-decorators'; const { get, isEmpty, Component } = Ember; export default Component.extend(StringBuffer, { classNameBindings: [':gutter'], rerenderTriggers: ['expanded'], // Roll up links to avoid duplicates @computed('links') collapsed(links) { const seen = {}; const result = []; if (!isEmpty(links)) { links.forEach(function(l) { const title = get(l, 'title'); if (!seen[title]) { result.pushObject(l); seen[title] = true; } }); } return result; }, renderString(buffer) { const links = this.get('collapsed'); const collapsed = !this.get('expanded'); if (!isEmpty(links)) { let toRender = links; if (collapsed) { toRender = toRender.slice(0, MAX_SHOWN); } buffer.push("'); } if (this.get('canReplyAsNewTopic')) { buffer.push(`${iconHTML('plus')}${I18n.t('post.reply_as_new_topic')}`); } }, click(e) { const $target = $(e.target); if ($target.hasClass('toggle-more')) { this.toggleProperty('expanded'); return false; } else if ($target.closest('.reply-new').length) { this.sendAction('newTopicAction', this.get('post')); return false; } return true; } });