mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-24 08:09:13 -05:00
FIX: Stop endless loading at the bottom of a user's stream.
This commit is contained in:
parent
d9e5c2317f
commit
bddd7f5ea3
2 changed files with 12 additions and 10 deletions
|
@ -65,16 +65,19 @@ Discourse.UserStream = Discourse.Model.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
findItems: function() {
|
findItems: function() {
|
||||||
var userStream = this;
|
var self = this;
|
||||||
if(this.get('loading')) { return Ember.RSVP.reject(); }
|
|
||||||
|
|
||||||
this.set('loading', true);
|
|
||||||
|
|
||||||
var url = this.get('baseUrl');
|
var url = this.get('baseUrl');
|
||||||
if (this.get('filterParam')) {
|
if (this.get('filterParam')) {
|
||||||
url += "&filter=" + this.get('filterParam');
|
url += "&filter=" + this.get('filterParam');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't load the same stream twice. We're probably at the end.
|
||||||
|
var lastLoadedUrl = this.get('lastLoadedUrl');
|
||||||
|
if (lastLoadedUrl === url) { return Ember.RSVP.resolve(); }
|
||||||
|
|
||||||
|
if (this.get('loading')) { return Ember.RSVP.resolve(); }
|
||||||
|
this.set('loading', true);
|
||||||
return Discourse.ajax(url, {cache: 'false'}).then( function(result) {
|
return Discourse.ajax(url, {cache: 'false'}).then( function(result) {
|
||||||
if (result && result.user_actions) {
|
if (result && result.user_actions) {
|
||||||
var copy = Em.A();
|
var copy = Em.A();
|
||||||
|
@ -82,14 +85,15 @@ Discourse.UserStream = Discourse.Model.extend({
|
||||||
copy.pushObject(Discourse.UserAction.create(action));
|
copy.pushObject(Discourse.UserAction.create(action));
|
||||||
});
|
});
|
||||||
|
|
||||||
userStream.get('content').pushObjects(Discourse.UserAction.collapseStream(copy));
|
self.get('content').pushObjects(Discourse.UserAction.collapseStream(copy));
|
||||||
userStream.setProperties({
|
self.setProperties({
|
||||||
loaded: true,
|
loaded: true,
|
||||||
itemsLoaded: userStream.get('itemsLoaded') + result.user_actions.length
|
itemsLoaded: self.get('itemsLoaded') + result.user_actions.length
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).finally(function() {
|
}).finally(function() {
|
||||||
userStream.set('loading', false);
|
self.set('loading', false);
|
||||||
|
self.set('lastLoadedUrl', url);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,6 @@ export default Ember.View.extend(Discourse.LoadMore, {
|
||||||
stream.findItems().then(function() {
|
stream.findItems().then(function() {
|
||||||
self.set('loading', false);
|
self.set('loading', false);
|
||||||
self.get('eyeline').flushRest();
|
self.get('eyeline').flushRest();
|
||||||
}).catch(function() {
|
|
||||||
// If we were already loading...
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue