FIX: Stop endless loading at the bottom of a user's stream.

This commit is contained in:
Robin Ward 2014-07-21 14:13:17 -04:00
parent d9e5c2317f
commit bddd7f5ea3
2 changed files with 12 additions and 10 deletions

View file

@ -65,16 +65,19 @@ Discourse.UserStream = Discourse.Model.extend({
},
findItems: function() {
var userStream = this;
if(this.get('loading')) { return Ember.RSVP.reject(); }
this.set('loading', true);
var self = this;
var url = this.get('baseUrl');
if (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) {
if (result && result.user_actions) {
var copy = Em.A();
@ -82,14 +85,15 @@ Discourse.UserStream = Discourse.Model.extend({
copy.pushObject(Discourse.UserAction.create(action));
});
userStream.get('content').pushObjects(Discourse.UserAction.collapseStream(copy));
userStream.setProperties({
self.get('content').pushObjects(Discourse.UserAction.collapseStream(copy));
self.setProperties({
loaded: true,
itemsLoaded: userStream.get('itemsLoaded') + result.user_actions.length
itemsLoaded: self.get('itemsLoaded') + result.user_actions.length
});
}
}).finally(function() {
userStream.set('loading', false);
self.set('loading', false);
self.set('lastLoadedUrl', url);
});
}

View file

@ -18,8 +18,6 @@ export default Ember.View.extend(Discourse.LoadMore, {
stream.findItems().then(function() {
self.set('loading', false);
self.get('eyeline').flushRest();
}).catch(function() {
// If we were already loading...
});
}
}