Skip to content

Commit

Permalink
Make sure the pagination metadata for the action collection is correc…
Browse files Browse the repository at this point in the history
…t after new actions are fetched

- On new actions, we were resetting the metadata back to page one, and therefore potentially fetching the wrong page when scrolling through the infinite scroll of the actions
  • Loading branch information
atogle committed Jan 6, 2014
1 parent 795e252 commit 42b9676
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9.7
3.9.8
26 changes: 22 additions & 4 deletions src/sa_web/static/js/views/activity-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,20 @@ var Shareabouts = Shareabouts || {};
},

checkForNewActivity: function() {
var options = {};

var options = {
remove: false
},
meta = this.collection.metadata;

// The metadata will be reset to page 1 if a new action has been added.
// We need to cache the current page information so that when we will
// fetch to correct page when we scroll to the next break.
options.complete = _.bind(function() {
// The total length may have changed, so don't overwrite it!
meta.length = this.collection.metadata.length;
this.collection.metadata = meta;
this.fetching = false;

// After a check for activity has completed, no matter the result,
// schedule another.
if (this.newContentTimeout) {
Expand All @@ -57,7 +68,14 @@ var Shareabouts = Shareabouts || {};
this.newContentTimeout = setTimeout(_.bind(this.checkForNewActivity, this), this.interval);
}, this);

this.collection.fetch(options);
// Don't fetch new activity if we're in the middle of fetching a new page.
if (!this.fetching) {
this.fetching = true;
this.collection.fetch(options);
} else {
// Let's wait 5 seconds and try again.
this.newContentTimeout = setTimeout(_.bind(this.checkForNewActivity, this), 5000);
}
},

onScroll: function(evt) {
Expand All @@ -71,7 +89,7 @@ var Shareabouts = Shareabouts || {};
self.fetching = true;
this.collection.fetchNextPage(
function() { _.delay(notFetching, notFetchingDelay); },
function() {_.delay(notFetching, notFetchingDelay); }
function() { _.delay(notFetching, notFetchingDelay); }
);
}
},
Expand Down

0 comments on commit 42b9676

Please sign in to comment.