This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/components/topic-post-badges.js.es6
2019-05-27 10:15:39 +02:00

33 lines
985 B
JavaScript

import { bufferedRender } from "discourse-common/lib/buffered-render";
// Creates a link
function link(buffer, prop, url, cssClass, i18nKey, text) {
if (!prop) {
return;
}
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 Ember.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);
}
})
);