FIX: Don't try to load badges if there none left (#13695)

Converted `actions` hash to `@action` and added:

```
if (!this.canLoadMore) {
  return;
}
```
This commit is contained in:
Jarek Radosz 2021-07-14 06:42:31 +02:00 committed by GitHub
parent 068889cb5f
commit c3045e6828
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,7 @@
import EmberObject, { action } from "@ember/object";
import Controller, { inject as controller } from "@ember/controller";
import discourseComputed, { observes } from "discourse-common/utils/decorators";
import Badge from "discourse/models/badge";
import EmberObject from "@ember/object";
import I18n from "I18n";
import UserBadge from "discourse/models/user-badge";
@ -50,35 +50,6 @@ export default Controller.extend({
return this.siteSettings.enable_badges && hasTitleBadges && hasBadge;
},
actions: {
loadMore() {
if (this.loadingMore) {
return;
}
this.set("loadingMore", true);
const userBadges = this.userBadges;
UserBadge.findByBadgeId(this.get("model.id"), {
offset: userBadges.length,
username: this.username,
})
.then((result) => {
userBadges.pushObjects(result);
if (userBadges.length === 0) {
this.set("noMoreBadges", true);
}
})
.finally(() => {
this.set("loadingMore", false);
});
},
toggleSetUserTitle() {
return this.toggleProperty("hiddenSetTitle");
},
},
@discourseComputed("noMoreBadges", "grantCount", "userBadges.length")
canLoadMore(noMoreBadges, grantCount, userBadgeLength) {
if (noMoreBadges) {
@ -96,4 +67,37 @@ export default Controller.extend({
_showFooter() {
this.set("application.showFooter", !this.canLoadMore);
},
@action
loadMore() {
if (!this.canLoadMore) {
return;
}
if (this.loadingMore) {
return;
}
this.set("loadingMore", true);
const userBadges = this.userBadges;
UserBadge.findByBadgeId(this.get("model.id"), {
offset: userBadges.length,
username: this.username,
})
.then((result) => {
userBadges.pushObjects(result);
if (userBadges.length === 0) {
this.set("noMoreBadges", true);
}
})
.finally(() => {
this.set("loadingMore", false);
});
},
@action
toggleSetUserTitle() {
return this.toggleProperty("hiddenSetTitle");
},
});