Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate all React functionality to use @wordpress/element with dependency extraction #2756

Merged
merged 11 commits into from
May 17, 2022
Prev Previous commit
Next Next commit
Revert to regular fetch for Autosuggest.
  • Loading branch information
JakePT committed May 17, 2022
commit 94f2b9369c3c339763f4b624b9a95e26218a4b1c
19 changes: 9 additions & 10 deletions assets/js/autosuggest.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/* eslint-disable camelcase, no-underscore-dangle, no-use-before-define */

/**
* WordPress dependencies.
*/
import apiFetch from '@wordpress/api-fetch';

/**
* Internal dependencies.
*/
Expand Down Expand Up @@ -173,13 +168,11 @@ function buildSearchQuery(searchText, placeholder, { query }) {
async function esSearch(query, searchTerm) {
const fetchConfig = {
body: query,
credentials: 'omit',
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
method: 'POST',
mode: 'cors',
url: epas.endpointUrl,
};

if (epas?.http_headers && typeof epas.http_headers === 'object') {
Expand All @@ -194,7 +187,13 @@ async function esSearch(query, searchTerm) {
}

try {
const data = await apiFetch(fetchConfig);
const response = await fetch(epas.endpointUrl, fetchConfig);

if (!response.ok) {
throw Error(response.statusText);
}

const data = await response.json();

// allow for filtered data before returning it to
// be output on the front end
Expand Down