Skip to content

Commit 20afa11

Browse files
committed
Move QueryClientProvider to top component
1 parent 8e55218 commit 20afa11

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/Elastic.Documentation.Site/Assets/web-components/SearchOrAskAi/Search/useSearchQuery.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ export const useSearchQuery = () => {
2424
return useQuery<SearchResponse>({
2525
queryKey: ['search', { searchTerm: debouncedSearchTerm }],
2626
queryFn: async () => {
27+
if (!debouncedSearchTerm || debouncedSearchTerm.length < 1) {
28+
return SearchResponse.parse({ results: [], totalResults: 0 })
29+
}
30+
2731
const response = await fetch(
2832
'/docs/_api/v1/search?q=' +
2933
encodeURIComponent(debouncedSearchTerm)

src/Elastic.Documentation.Site/Assets/web-components/SearchOrAskAi/SearchOrAskAi.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { SearchOrAskAiButton } from './SearchOrAskAiButton'
22
import r2wc from '@r2wc/react-to-web-component'
3+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
34
import * as React from 'react'
45
import { StrictMode } from 'react'
56

67
const SearchOrAskAi = () => {
8+
const queryClient = new QueryClient()
79
return (
810
<StrictMode>
9-
<SearchOrAskAiButton />
11+
<QueryClientProvider client={queryClient}>
12+
<SearchOrAskAiButton />
13+
</QueryClientProvider>
1014
</StrictMode>
1115
)
1216
}

src/Elastic.Documentation.Site/Assets/web-components/SearchOrAskAi/SearchOrAskAiModal.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,15 @@ import {
1010
EuiHorizontalRule,
1111
} from '@elastic/eui'
1212
import { css } from '@emotion/react'
13-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
1413
import * as React from 'react'
1514

1615
export const SearchOrAskAiModal = () => {
1716
const searchTerm = useSearchTerm()
1817
const askAiTerm = useAskAiTerm()
1918
const { setSearchTerm, submitAskAiTerm } = useSearchActions()
2019

21-
const queryClient = new QueryClient()
22-
2320
return (
24-
<QueryClientProvider client={queryClient}>
21+
<>
2522
<EuiFieldSearch
2623
fullWidth
2724
placeholder="Search the docs or ask Elastic Docs AI Assistant"
@@ -59,6 +56,6 @@ export const SearchOrAskAiModal = () => {
5956
This feature is in beta. Got feedback? We'd love to hear it!
6057
</EuiText>
6158
</div>
62-
</QueryClientProvider>
59+
</>
6360
)
6461
}

0 commit comments

Comments
 (0)