* DEV: Fix the function prototype observers deprecation
DEPRECATION: Function prototype extensions have been deprecated, please migrate from function(){}.observes('foo') to observer('foo', function() {}). [deprecation id: function-prototype-extensions.observes] See https://deprecations.emberjs.com/v3.x/#toc_function-prototype-extensions-observes for more details.
* DEV: Fix the function prototype event listeners deprecation
DEPRECATION: Function prototype extensions have been deprecated, please migrate from function(){}.on('foo') to on('foo', function() {}). [deprecation id: function-prototype-extensions.on] See https://deprecations.emberjs.com/v3.x/#toc_function-prototype-extensions-on for more details.
* DEV: Simplify `default as` imports
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
72 lines
1.5 KiB
JavaScript
72 lines
1.5 KiB
JavaScript
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
|
import { inject } from "@ember/controller";
|
|
import Controller from "@ember/controller";
|
|
|
|
// Lists of topics on a user's page.
|
|
export default Controller.extend({
|
|
application: inject(),
|
|
|
|
hideCategory: false,
|
|
showPosters: false,
|
|
incomingCount: 0,
|
|
channel: null,
|
|
tagsForUser: null,
|
|
|
|
init() {
|
|
this._super(...arguments);
|
|
|
|
this.newIncoming = [];
|
|
},
|
|
|
|
saveScrollPosition: function() {
|
|
this.session.set("topicListScrollPosition", $(window).scrollTop());
|
|
},
|
|
|
|
@observes("model.canLoadMore")
|
|
_showFooter: function() {
|
|
this.set("application.showFooter", !this.get("model.canLoadMore"));
|
|
},
|
|
|
|
@discourseComputed("incomingCount")
|
|
hasIncoming(incomingCount) {
|
|
return incomingCount > 0;
|
|
},
|
|
|
|
subscribe(channel) {
|
|
this.set("channel", channel);
|
|
|
|
this.messageBus.subscribe(channel, data => {
|
|
if (this.newIncoming.indexOf(data.topic_id) === -1) {
|
|
this.newIncoming.push(data.topic_id);
|
|
this.incrementProperty("incomingCount");
|
|
}
|
|
});
|
|
},
|
|
|
|
unsubscribe() {
|
|
const channel = this.channel;
|
|
if (channel) this.messageBus.unsubscribe(channel);
|
|
this._resetTracking();
|
|
this.set("channel", null);
|
|
},
|
|
|
|
_resetTracking() {
|
|
this.setProperties({
|
|
newIncoming: [],
|
|
incomingCount: 0
|
|
});
|
|
},
|
|
|
|
actions: {
|
|
loadMore: function() {
|
|
this.model.loadMore();
|
|
},
|
|
|
|
showInserted() {
|
|
this.model.loadBefore(this.newIncoming);
|
|
this._resetTracking();
|
|
return false;
|
|
}
|
|
}
|
|
});
|