DEV: Remove buffered rendering from topic-post-badges

This is another refactoring in the multi-step process to remove all uses
of our custom Render Buffer.

Previous commit: f5cca4930d in this
series.

This commit affects the display of some of the unread, new, and unseen
badges in topic lists like when then "show subcategory list above topics
in this category" option is checked.
This commit is contained in:
Blake Erickson 2019-12-12 07:03:53 -07:00
parent b6589f203b
commit ea6326c860
2 changed files with 23 additions and 30 deletions

View File

@ -1,33 +1,17 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { bufferedRender } from "discourse-common/lib/buffered-render";
// Creates a link export default Component.extend({
function link(buffer, prop, url, cssClass, i18nKey, text) { tagName: "span",
if (!prop) { classNameBindings: [":topic-post-badges"],
return; rerenderTriggers: ["url", "unread", "newPosts", "unseen"],
newDotText: null,
init() {
this._super(...arguments);
this.set(
"newDotText",
this.currentUser && this.currentUser.trust_level > 0
? " "
: I18n.t("filters.new.lower_title")
);
} }
const title = I18n.t("topic." + i18nKey, { count: prop }); });
buffer.push(
`<a href="${url}" class="badge ${cssClass} badge-notification" title="${title}">${text ||
prop}</a>\n`
);
}
export default Component.extend(
bufferedRender({
tagName: "span",
classNameBindings: [":topic-post-badges"],
rerenderTriggers: ["url", "unread", "newPosts", "unseen"],
buildBuffer(buffer) {
const newDotText =
this.currentUser && this.currentUser.trust_level > 0
? " "
: I18n.t("filters.new.lower_title");
const url = this.url;
link(buffer, this.unread, url, "unread", "unread_posts");
link(buffer, this.newPosts, url, "new-posts", "new_posts");
link(buffer, this.unseen, url, "new-topic", "new", newDotText);
}
})
);

View File

@ -0,0 +1,9 @@
{{#if unread }}
&nbsp;<a href='{{url}}' class='badge badge-notification unread' title='{{i18n "topic.unread_posts" count=unread}}'>{{unread}}</a>
{{/if}}
{{#if newPosts}}
&nbsp;<a href='{{url}}' class='badge badge-notification new-posts' title='{{i18n "topic.total_unread_posts" count=newPosts}}'>{{newPosts}}</a>
{{/if}}
{{#if unseen}}
&nbsp;<a href='{{url}}' class='badge badge-notification new-topic' title='{{i18n "topic.new"}}'>{{newDotText}}</a>
{{/if}}