From 0b6c84e2929987372d6bbf2711925baddd8381c6 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 3 Sep 2014 12:22:18 -0400 Subject: [PATCH] UX: Remove background color from new badge. DRY up lots of repeated code for rendering badges on topics. --- .../components/topic-post-badges.js.es6 | 22 +++++++++++++++++++ .../components/basic-topic-list.js.handlebars | 13 ++++------- .../discovery/categories.js.handlebars | 7 +----- .../list/topic_list_item.js.handlebars | 10 +-------- .../components/basic-topic-list.js.handlebars | 15 +++++-------- .../mobile/discovery/categories.js.handlebars | 11 +--------- .../mobile/list/topic_list_item.js.handlebars | 13 ++++------- .../common/components/badges.css.scss | 6 ++++- 8 files changed, 44 insertions(+), 53 deletions(-) create mode 100644 app/assets/javascripts/discourse/components/topic-post-badges.js.es6 diff --git a/app/assets/javascripts/discourse/components/topic-post-badges.js.es6 b/app/assets/javascripts/discourse/components/topic-post-badges.js.es6 new file mode 100644 index 00000000000..cf21baa2a41 --- /dev/null +++ b/app/assets/javascripts/discourse/components/topic-post-badges.js.es6 @@ -0,0 +1,22 @@ + +// Creates a link +function link(buffer, prop, url, cssClass, i18nKey, text) { + if (!prop) { return; } + + var title = I18n.t("topic." + i18nKey, {count: prop}); + buffer.push("" + (text || prop) + "\n"); +} + +export default Ember.Component.extend({ + tagName: 'span', + classNameBindings: [':topic-post-badges'], + _shouldRerender: Discourse.View.renderIfChanged('url', 'unread', 'newPosts', 'unseen'), + + render: function(buffer) { + var url = this.get('url'); + + link(buffer, this.get('unread'), url, 'unread', 'unread_posts'); + link(buffer, this.get('newPosts'), url, 'new-posts', 'new_posts'); + link(buffer, this.get('unseen'), url, 'new-topic', 'new', I18n.t('filters.new.lower_title')); + } +}); diff --git a/app/assets/javascripts/discourse/templates/components/basic-topic-list.js.handlebars b/app/assets/javascripts/discourse/templates/components/basic-topic-list.js.handlebars index 25ea859ea92..4cfb562989c 100644 --- a/app/assets/javascripts/discourse/templates/components/basic-topic-list.js.handlebars +++ b/app/assets/javascripts/discourse/templates/components/basic-topic-list.js.handlebars @@ -22,15 +22,10 @@ {{topic-status topic=topic}} {{{unbound topic.fancy_title}}} - {{#if unread}} - {{unbound topic.unread}} - {{/if}} - {{#if topic.new_posts}} - {{unbound topic.new_posts}} - {{/if}} - {{#if topic.unseen}} - {{i18n filters.new.lower_title}} - {{/if}} + {{topic-post-badges unread=unread + newPosts=topic.new_posts + unseen=topic.unseen + url=topic.lastUnreadUrl}} {{#unless controller.hideCategory}} diff --git a/app/assets/javascripts/discourse/templates/discovery/categories.js.handlebars b/app/assets/javascripts/discourse/templates/discovery/categories.js.handlebars index b2360ab39b5..9acc57189dc 100644 --- a/app/assets/javascripts/discourse/templates/discovery/categories.js.handlebars +++ b/app/assets/javascripts/discourse/templates/discovery/categories.js.handlebars @@ -48,12 +48,7 @@