DEV: Remove buffered rendering from admin-directory toggle

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

Previous commit: d0ad5ecc6d in this
series.

This commit affects the table header sorting on the admin directory page.
It is just a refactor and should not change any functionality.
This commit is contained in:
Blake Erickson 2019-11-25 18:02:55 -07:00
parent cfa6ec8034
commit e0199e8094
2 changed files with 27 additions and 32 deletions

View File

@ -1,36 +1,30 @@
import Component from "@ember/component";
import { iconHTML } from "discourse-common/lib/icon-library";
import { bufferedRender } from "discourse-common/lib/buffered-render";
export default Component.extend(
bufferedRender({
tagName: "th",
classNames: ["sortable"],
rerenderTriggers: ["order", "ascending"],
buildBuffer(buffer) {
const icon = this.icon;
if (icon) {
buffer.push(iconHTML(icon));
}
buffer.push(I18n.t(this.i18nKey));
if (this.field === this.order) {
buffer.push(iconHTML(this.ascending ? "chevron-up" : "chevron-down"));
}
},
click() {
const currentOrder = this.order;
const field = this.field;
if (currentOrder === field) {
this.set("ascending", this.ascending ? null : true);
} else {
this.setProperties({ order: field, ascending: null });
}
export default Component.extend({
tagName: "th",
classNames: ["sortable"],
chevronIcon: null,
toggleProperties() {
if (this.order === this.field) {
this.set("ascending", this.ascending ? null : true);
} else {
this.setProperties({ order: this.field, ascending: null });
}
})
);
},
toggleChevron() {
if (this.order === this.field) {
let chevron = iconHTML(this.ascending ? "chevron-up" : "chevron-down");
this.set("chevronIcon", `${chevron}`.htmlSafe());
} else {
this.set("chevronIcon", null);
}
},
click() {
this.toggleProperties();
},
didReceiveAttrs() {
this._super(...arguments);
this.toggleChevron();
}
});

View File

@ -0,0 +1 @@
<span class="header-contents">{{i18n this.i18nKey}}{{chevronIcon}}</span>