Skip to content

Commit

Permalink
fix: load more button - remove amp-layout container, append each new …
Browse files Browse the repository at this point in the history
…article individually. (#375)
  • Loading branch information
Jefferson Rabb authored Feb 20, 2020
1 parent 23e84d2 commit efee9dc
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions amp/homepage-articles/view.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let isFetching = false;
let isEndOfData = false;
buildLoadMoreHandler( document.querySelector( '.wp-block-newspack-blocks-homepage-articles') );
buildLoadMoreHandler( document.querySelector( '.wp-block-newspack-blocks-homepage-articles' ) );
function buildLoadMoreHandler( blockWrapperEl ) {
const btnEl = blockWrapperEl.querySelector( '[data-next]' );
if ( ! btnEl ) {
Expand All @@ -26,10 +26,11 @@ function buildLoadMoreHandler( blockWrapperEl ) {
} );
} );
if ( isPostsDataValid( data ) ) {
const postsHTML = data.items.map( item => item.html ).join( '' );
const ampLayout = document.createElement( 'amp-layout' );
ampLayout.innerHTML = postsHTML;
postsContainerEl.appendChild( ampLayout );
data.items.forEach( item => {
const tempDIV = document.createElement( 'div' );
tempDIV.innerHTML = item.html.trim();
postsContainerEl.appendChild( tempDIV.childNodes[ 0 ] );
} );
if ( data.next ) {
btnEl.setAttribute( 'data-next', data.next );
}
Expand All @@ -40,7 +41,7 @@ function buildLoadMoreHandler( blockWrapperEl ) {
isFetching = false;
blockWrapperEl.classList.remove( 'is-loading' );
}
};
}
function onError() {
isFetching = false;
blockWrapperEl.classList.remove( 'is-loading' );
Expand Down

0 comments on commit efee9dc

Please sign in to comment.