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

feat(docs): prepare query interception with debounce #2342

Merged
merged 3 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"react-is": "^18.2.0",
"react-monaco-editor": "^0.54.0",
"sass": "^1.69.5",
"url": "^0.11.3"
"url": "^0.11.3",
"lodash": "^4.17.21"
}
}
36 changes: 35 additions & 1 deletion website/src/theme/SearchBar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import Translate from '@docusaurus/Translate';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import translations from '@theme/SearchTranslations';
import debounce from 'lodash.debounce';

let DocSearchModal = null;

Expand Down Expand Up @@ -133,7 +134,40 @@ function DocSearch({ contextualSearch, externalUrlRegex, ...props }) {
'docusaurus',
siteMetadata.docusaurusVersion,
);
return searchClient;
const debouncedSearch = debounce(async (requests, resolve) => {

// const requestForApi = requests.map((request) => request.query);

// Change url to your api
// const response = await fetch('http://localhost:3001/angolia', {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json',
// },
// body: JSON.stringify(requestForApi),
// });

// const apiData = await response.json();

// const requestsForAngolia = requests.map((request) => ({
// ...request,
// query: apiData.message,
// }));

// Change requests to requestsForAngolia
const results = await searchClient.search(requests);

resolve(results);
}, 300);

const enhancedClient = {
...searchClient,
search: (requests) =>
new Promise((resolve) => {
debouncedSearch(requests, resolve);
}),
};
return enhancedClient;
},
[siteMetadata.docusaurusVersion],
);
Expand Down
Loading