DEV: Export the default behaviour of a topic-list-item so it can be reused by the discourse-assign plugin (#7433)

This commit is contained in:
Roman Rizzi 2019-04-30 15:36:54 -03:00 committed by GitHub
parent e0db323efb
commit 404666c9e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,17 +29,8 @@ export function navigateToTopic(topic, href) {
return false;
}
export default Ember.Component.extend(
bufferedRender({
rerenderTriggers: ["bulkSelectEnabled", "topic.pinned"],
export const ListItemDefaults = {
tagName: "tr",
classNameBindings: [
":topic-list-item",
"unboundClassNames",
"topic.visited"
],
attributeBindings: ["data-topic-id"],
"data-topic-id": Ember.computed.alias("topic.id"),
@computed
newDotText() {
@ -48,21 +39,6 @@ export default Ember.Component.extend(
: I18n.t("filters.new.lower_title");
},
actions: {
toggleBookmark() {
this.get("topic")
.toggleBookmark()
.finally(() => this.rerenderBuffer());
}
},
buildBuffer(buffer) {
const template = findRawTemplate("list/topic-list-item");
if (template) {
buffer.push(template(this));
}
},
@computed("topic", "lastVisitedTopic")
unboundClassNames(topic, lastVisitedTopic) {
let classes = [];
@ -125,10 +101,7 @@ export default Ember.Component.extend(
}
}
if (
this.get("expandGloballyPinned") &&
this.get("topic.pinned_globally")
) {
if (this.get("expandGloballyPinned") && this.get("topic.pinned_globally")) {
return true;
}
@ -176,9 +149,6 @@ export default Ember.Component.extend(
navigateToTopic,
// Can be overwritten by plugins to handle clicks on other parts of the row
unhandledRowClick() {},
highlight(opts = { isLastViewedTopic: false }) {
const $topic = this.$();
$topic
@ -199,5 +169,36 @@ export default Ember.Component.extend(
this.highlight();
}
}.on("didInsertElement")
};
export default Ember.Component.extend(
ListItemDefaults,
bufferedRender({
rerenderTriggers: ["bulkSelectEnabled", "topic.pinned"],
classNameBindings: [
":topic-list-item",
"unboundClassNames",
"topic.visited"
],
attributeBindings: ["data-topic-id"],
"data-topic-id": Ember.computed.alias("topic.id"),
actions: {
toggleBookmark() {
this.get("topic")
.toggleBookmark()
.finally(() => this.rerenderBuffer());
}
},
buildBuffer(buffer) {
const template = findRawTemplate("list/topic-list-item");
if (template) {
buffer.push(template(this));
}
},
// Can be overwritten by plugins to handle clicks on other parts of the row
unhandledRowClick() {}
})
);