Skip to content

Commit

Permalink
HA: Dumb down handling of exclude_ids (#340)
Browse files Browse the repository at this point in the history
* Dumb down handling of exclude_ids

Fixes IE11 incompatibility with `URL` api.

UI will now always add all IDs of displayed posts, the endpoint will always remove it from its next url.

* Encode URL before using it.

Props @WunderBart.
  • Loading branch information
obenland authored Jan 22, 2020
1 parent b3cc58e commit 2faed01
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ function( $attribute ) {
$attributes
),
[
'page' => $next_page,
'amp' => $request->get_param( 'amp' ),
'exclude_ids' => false,
'page' => $next_page,
'amp' => $request->get_param( 'amp' ),
]
),
rest_url( '/newspack-blocks/v1/articles' )
Expand Down
9 changes: 4 additions & 5 deletions src/blocks/homepage-articles/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ function buildLoadMoreHandler( blockWrapperEl ) {
blockWrapperEl.classList.remove( 'is-error' );
blockWrapperEl.classList.add( 'is-loading' );

const requestURL = new URL( btnEl.getAttribute( 'data-next' ) );
// Set currently rendered posts' IDs as a query param (e.g. exclude_ids=1,2,3)
const requestURL =
btnEl.getAttribute( 'data-next' ) + '&exclude_ids=' + getRenderedPostsIds().join( ',' );

// Set currenty rendered posts' IDs as a query param (e.g. exclude_ids=1,2,3)
requestURL.searchParams.set( 'exclude_ids', getRenderedPostsIds().join( ',' ) );

fetchWithRetry( { url: requestURL.toString(), onSuccess, onError }, fetchRetryCount );
fetchWithRetry( { url: encodeURI( requestURL ), onSuccess, onError }, fetchRetryCount );

/**
* @param {Object} data Post data
Expand Down

0 comments on commit 2faed01

Please sign in to comment.