mirror of
https://github.com/discourse/discourse.git
synced 2025-02-21 06:37:25 +08:00
REFACTOR: user-posts-stream model (#7657)
This commit is contained in:
parent
388433ec06
commit
63264158cf
@ -1,3 +1,4 @@
|
||||
import { on } from "ember-addons/ember-computed-decorators";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import { url } from "discourse/lib/computed";
|
||||
import UserAction from "discourse/models/user-action";
|
||||
@ -5,13 +6,14 @@ import UserAction from "discourse/models/user-action";
|
||||
export default Discourse.Model.extend({
|
||||
loaded: false,
|
||||
|
||||
_initialize: function() {
|
||||
@on("init")
|
||||
_initialize() {
|
||||
this.setProperties({
|
||||
itemsLoaded: 0,
|
||||
canLoadMore: true,
|
||||
content: []
|
||||
});
|
||||
}.on("init"),
|
||||
},
|
||||
|
||||
url: url(
|
||||
"user.username_lower",
|
||||
@ -40,7 +42,6 @@ export default Discourse.Model.extend({
|
||||
},
|
||||
|
||||
findItems() {
|
||||
const self = this;
|
||||
if (this.loading || !this.canLoadMore) {
|
||||
return Ember.RSVP.reject();
|
||||
}
|
||||
@ -48,21 +49,17 @@ export default Discourse.Model.extend({
|
||||
this.set("loading", true);
|
||||
|
||||
return ajax(this.url, { cache: false })
|
||||
.then(function(result) {
|
||||
.then(result => {
|
||||
if (result) {
|
||||
const posts = result.map(function(post) {
|
||||
return UserAction.create(post);
|
||||
});
|
||||
self.get("content").pushObjects(posts);
|
||||
self.setProperties({
|
||||
const posts = result.map(post => UserAction.create(post));
|
||||
this.content.pushObjects(posts);
|
||||
this.setProperties({
|
||||
loaded: true,
|
||||
itemsLoaded: self.get("itemsLoaded") + posts.length,
|
||||
itemsLoaded: this.itemsLoaded + posts.length,
|
||||
canLoadMore: posts.length > 0
|
||||
});
|
||||
}
|
||||
})
|
||||
.finally(function() {
|
||||
self.set("loading", false);
|
||||
});
|
||||
.finally(() => this.set("loading", false));
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user