DEV: Remove buffered rendering from user directory
This is another refactoring in the multi-step process to remove all uses
of our custom Render Buffer.
Previous commit: e0199e8094
in this
series.
This commit affects the table header sorting on the user directory page.
It is just a refactor and should not change any functionality.
This commit is contained in:
parent
5f7948ace6
commit
2673cad142
|
@ -1,48 +1,51 @@
|
|||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
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"],
|
||||
attributeBindings: ["title"],
|
||||
rerenderTriggers: ["order", "asc"],
|
||||
labelKey: null,
|
||||
export default Component.extend({
|
||||
tagName: "th",
|
||||
classNames: ["sortable"],
|
||||
attributeBindings: ["title"],
|
||||
labelKey: null,
|
||||
chevronIcon: null,
|
||||
columnIcon: null,
|
||||
|
||||
@discourseComputed("field", "labelKey")
|
||||
title(field, labelKey) {
|
||||
if (!labelKey) {
|
||||
labelKey = `directory.${this.field}`;
|
||||
}
|
||||
|
||||
return I18n.t(labelKey + "_long", { defaultValue: I18n.t(labelKey) });
|
||||
},
|
||||
|
||||
buildBuffer(buffer) {
|
||||
const icon = this.icon;
|
||||
if (icon) {
|
||||
buffer.push(iconHTML(icon));
|
||||
}
|
||||
|
||||
const field = this.field;
|
||||
buffer.push(I18n.t(this.labelKey || `directory.${field}`));
|
||||
|
||||
if (field === this.order) {
|
||||
buffer.push(iconHTML(this.asc ? "chevron-up" : "chevron-down"));
|
||||
}
|
||||
},
|
||||
|
||||
click() {
|
||||
const currentOrder = this.order,
|
||||
field = this.field;
|
||||
|
||||
if (currentOrder === field) {
|
||||
this.set("asc", this.asc ? null : true);
|
||||
} else {
|
||||
this.setProperties({ order: field, asc: null });
|
||||
}
|
||||
@discourseComputed("field", "labelKey")
|
||||
title(field, labelKey) {
|
||||
if (!labelKey) {
|
||||
labelKey = `directory.${this.field}`;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
return I18n.t(labelKey + "_long", { defaultValue: I18n.t(labelKey) });
|
||||
},
|
||||
|
||||
toggleProperties() {
|
||||
if (this.order === this.field) {
|
||||
this.set("asc", this.asc ? null : true);
|
||||
} else {
|
||||
this.setProperties({ order: this.field, asc: null });
|
||||
}
|
||||
},
|
||||
toggleChevron() {
|
||||
if (this.order === this.field) {
|
||||
let chevron = iconHTML(this.asc ? "chevron-up" : "chevron-down");
|
||||
this.set("chevronIcon", `${chevron}`.htmlSafe());
|
||||
} else {
|
||||
this.set("chevronIcon", null);
|
||||
}
|
||||
},
|
||||
click() {
|
||||
this.toggleProperties();
|
||||
},
|
||||
didReceiveAttrs() {
|
||||
this._super(...arguments);
|
||||
this.toggleChevron();
|
||||
},
|
||||
init() {
|
||||
this._super(...arguments);
|
||||
if (this.icon) {
|
||||
let columnIcon = iconHTML(this.icon);
|
||||
this.set("columnIcon", `${columnIcon}`.htmlSafe());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<span class="header-contents">{{columnIcon}}{{title}}{{chevronIcon}}</span>
|
Loading…
Reference in New Issue