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/controllers/group-activity-posts.js.es6
2019-05-27 10:15:39 +02:00

49 lines
1.3 KiB
JavaScript

import { observes } from "ember-addons/ember-computed-decorators";
import { fmt } from "discourse/lib/computed";
export default Ember.Controller.extend({
group: Ember.inject.controller(),
groupActivity: Ember.inject.controller(),
application: Ember.inject.controller(),
canLoadMore: true,
loading: false,
emptyText: fmt("type", "groups.empty.%@"),
actions: {
loadMore() {
if (!this.canLoadMore) {
return;
}
if (this.loading) {
return;
}
this.set("loading", true);
const posts = this.model;
if (posts && posts.length) {
const beforePostId = posts[posts.length - 1].get("id");
const group = this.get("group.model");
let categoryId = this.get("groupActivity.category_id");
const opts = { beforePostId, type: this.type, categoryId };
group
.findPosts(opts)
.then(newPosts => {
posts.addObjects(newPosts);
if (newPosts.length === 0) {
this.set("canLoadMore", false);
}
})
.finally(() => {
this.set("loading", false);
});
}
}
},
@observes("canLoadMore")
_showFooter() {
this.set("application.showFooter", !this.canLoadMore);
}
});