DEV: Convert UserStream model to native class syntax ()

This commit was created with a combination of the ember-native-class-codemod and manual cleanup
This commit is contained in:
David Taylor 2024-02-09 15:16:05 +00:00 committed by GitHub
parent d93debc634
commit 2af8f5708d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -6,15 +6,19 @@ import { emojiUnescape } from "discourse/lib/text";
import { escapeExpression } from "discourse/lib/utilities";
import RestModel from "discourse/models/rest";
import UserAction from "discourse/models/user-action";
import discourseComputed, { on } from "discourse-common/utils/decorators";
import discourseComputed from "discourse-common/utils/decorators";
export default RestModel.extend({
loaded: false,
export default class UserStream extends RestModel {
loaded = false;
itemsLoaded = 0;
content = [];
@on("init")
_initialize() {
this.setProperties({ itemsLoaded: 0, content: [] });
},
@url(
"itemsLoaded",
"user.username_lower",
"/user_actions.json?offset=%@&username=%@"
)
baseUrl;
@discourseComputed("filter")
filterParam(filter) {
@ -27,13 +31,7 @@ export default RestModel.extend({
}
return filter;
},
baseUrl: url(
"itemsLoaded",
"user.username_lower",
"/user_actions.json?offset=%@&username=%@"
),
}
filterBy(opts) {
this.setProperties(
@ -48,7 +46,7 @@ export default RestModel.extend({
);
return this.findItems();
},
}
@discourseComputed("baseUrl", "filterParam", "actingUsername")
nextFindUrl() {
@ -62,17 +60,17 @@ export default RestModel.extend({
}
return findUrl;
},
}
@discourseComputed("loaded", "content.[]")
noContent(loaded, content) {
return loaded && content.length === 0;
},
}
@discourseComputed("nextFindUrl", "lastLoadedUrl")
canLoadMore() {
return this.nextFindUrl !== this.lastLoadedUrl;
},
}
remove(userAction) {
// 1) remove the user action from the child groups
@ -93,7 +91,7 @@ export default RestModel.extend({
});
this.setProperties({ content, itemsLoaded: content.length });
},
}
findItems() {
if (!this.canLoadMore) {
@ -130,5 +128,5 @@ export default RestModel.extend({
lastLoadedUrl: findUrl,
})
);
},
});
}
}