Skip to content

Commit

Permalink
Implement reload after load failed
Browse files Browse the repository at this point in the history
  • Loading branch information
cathyxz committed Nov 20, 2018
1 parent 0349303 commit bc6d0ee
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions extensions/amp-list/0.1/amp-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,11 @@ export class AmpList extends AMP.BaseElement {
items = items.slice(0, maxLen);
}
return this.scheduleRender_(/** @type {!Array} */(items), !!opt_append);
}, error => {
throw user().createError('Error fetching amp-list', error);
});
}

return fetch.catch(error => {
if (opt_append) {
// TODO: Handle load failed
this.handleLoadMoreFailed_();
} else {
this.showFallback_(error);
Expand All @@ -396,7 +393,8 @@ export class AmpList extends AMP.BaseElement {
if (this.loadMoreFailedElement_) {
this.setLoadMoreFailed_();
} else {
this.setLoadMore_();
// TODO (#14060): implement reload for append after failed load
this.setLoadMoreReload_();
}
}
/**
Expand Down Expand Up @@ -699,7 +697,6 @@ export class AmpList extends AMP.BaseElement {
this.maybeSetupLoadMoreAuto_();
}
if (this.loadMoreOverflow_) {
debugger;
this.mutateElement(() => {
this.loadMoreOverflow_.classList.toggle('amp-visible', true);
listen(this.loadMoreOverflow_, 'click', () => this.loadMoreCallback_());
Expand All @@ -712,6 +709,29 @@ export class AmpList extends AMP.BaseElement {
}
}

/**
* @private
*/
setLoadMoreReload_() {
if (this.loadMoreOverflow_) {
this.mutateElement(() => {
this.loadMoreOverflow_.classList.toggle('amp-visible', true);
listen(this.loadMoreOverflow_, 'click',
() => this.loadMoreReloadCallback_());
});
}
}

/**
* @return {!Promise}
* @private
*/
loadMoreReloadCallback_() {
this.toggleLoadMoreLoading_(true);
return this.fetchList_(/* opt_append */ true)
.then(() => this.toggleLoadMoreLoading_(false));
}

/**
* @private
*/
Expand Down

0 comments on commit bc6d0ee

Please sign in to comment.