mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Fix infinate loading of group posts (#5296)
This commit is contained in:
@@ -1,13 +1,17 @@
|
|||||||
|
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
||||||
import { fmt } from 'discourse/lib/computed';
|
import { fmt } from 'discourse/lib/computed';
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
group: Ember.inject.controller(),
|
group: Ember.inject.controller(),
|
||||||
groupActivity: Ember.inject.controller(),
|
groupActivity: Ember.inject.controller(),
|
||||||
|
application: Ember.inject.controller(),
|
||||||
|
canLoadMore: true,
|
||||||
loading: false,
|
loading: false,
|
||||||
emptyText: fmt('type', 'groups.empty.%@'),
|
emptyText: fmt('type', 'groups.empty.%@'),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
loadMore() {
|
loadMore() {
|
||||||
|
if (!this.get('canLoadMore')) { return; }
|
||||||
if (this.get('loading')) { return; }
|
if (this.get('loading')) { return; }
|
||||||
this.set('loading', true);
|
this.set('loading', true);
|
||||||
const posts = this.get('model');
|
const posts = this.get('model');
|
||||||
@@ -20,9 +24,18 @@ export default Ember.Controller.extend({
|
|||||||
|
|
||||||
group.findPosts(opts).then(newPosts => {
|
group.findPosts(opts).then(newPosts => {
|
||||||
posts.addObjects(newPosts);
|
posts.addObjects(newPosts);
|
||||||
|
if(newPosts.length === 0) {
|
||||||
|
this.set('canLoadMore', false);
|
||||||
|
}
|
||||||
|
}).finally(() => {
|
||||||
this.set('loading', false);
|
this.set('loading', false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
@observes('canLoadMore')
|
||||||
|
_showFooter() {
|
||||||
|
this.set("application.showFooter", !this.get("canLoadMore"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export function buildGroupPage(type) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
setupController(controller, model) {
|
setupController(controller, model) {
|
||||||
this.controllerFor('group-activity-posts').setProperties({ model, type });
|
this.controllerFor('group-activity-posts').setProperties({ model, type, canLoadMore: true });
|
||||||
this.controllerFor("group").set("showing", type);
|
this.controllerFor("group").set("showing", type);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user