From b95c68c4ce06fb439b517d88d277aa4e70b6bfd1 Mon Sep 17 00:00:00 2001 From: Matias Benary Date: Thu, 28 Nov 2024 18:45:22 -0300 Subject: [PATCH 1/2] feat(docs): prepare query interception with debounce --- package.json | 5 ++++ website/src/theme/SearchBar/index.js | 36 +++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 00000000000..4a981e852d4 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "lodash": "^4.17.21" + } +} diff --git a/website/src/theme/SearchBar/index.js b/website/src/theme/SearchBar/index.js index d0e7d266d40..0409582218c 100644 --- a/website/src/theme/SearchBar/index.js +++ b/website/src/theme/SearchBar/index.js @@ -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; @@ -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], ); From 6b1561fae188a431498322844db12950da8ba116 Mon Sep 17 00:00:00 2001 From: Matias Benary Date: Thu, 28 Nov 2024 18:48:06 -0300 Subject: [PATCH 2/2] feat(docs): prepare query interception with debounce --- package.json | 5 ----- website/package.json | 3 ++- 2 files changed, 2 insertions(+), 6 deletions(-) delete mode 100644 package.json diff --git a/package.json b/package.json deleted file mode 100644 index 4a981e852d4..00000000000 --- a/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "dependencies": { - "lodash": "^4.17.21" - } -} diff --git a/website/package.json b/website/package.json index ec9a2ef068c..e55c20aaff1 100644 --- a/website/package.json +++ b/website/package.json @@ -58,6 +58,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" } }