Skip to content

Commit

Permalink
feat: add language facetFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
RobsonOlv committed Feb 5, 2024
1 parent c498644 commit 4f4cb99
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/components/search-input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { Configure, InstantSearch } from 'react-instantsearch-dom'
import SearchBox from './search-box'
import Results from './results-box'
import { Box } from '@vtex/brand-ui'
import { useRef, useState } from 'react'
import { useContext, useRef, useState } from 'react'
import useClickOutside from 'utils/hooks/useClickOutside'
import { searchClient, searchIndex } from 'utils/config/search-config'
import { LibraryContext } from 'utils/context/libraryContext'

export default function SearchInput() {
const { locale } = useContext(LibraryContext)
const [focusOut, setfocusOut] = useState<{ modaltoggle: boolean }>({
modaltoggle: true,
})
Expand All @@ -19,7 +21,10 @@ export default function SearchInput() {

return (
<InstantSearch searchClient={searchClient} indexName={searchIndex}>
<Configure clickAnalytics={true} />
{
searchClient.instantSearchConfigs && <Configure {...searchClient.instantSearchConfigs} />
}
<Configure clickAnalytics={true} facetFilters={[`language:${locale}`]} />
<Box onFocus={() => setfocusOut({ modaltoggle: true })} ref={resultsBox}>
<SearchBox changeFocus={changeFocus} />
{focusOut.modaltoggle && <Results changeFocus={changeFocus} />}
Expand Down
4 changes: 3 additions & 1 deletion src/utils/config/search-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ interface AlgoliaConfig {
algoliaOptions?: AlgoliaSearchOptions
// eslint-disable-next-line @typescript-eslint/no-explicit-any
customOptions?: any
instantSearchConfigs?: any
}

const createAlgoliaClient = (config: AlgoliaConfig) => {
const { apiKey, appId, index, algoliaOptions, customOptions } = config
const { apiKey, appId, index, algoliaOptions, customOptions, instantSearchConfigs } = config
searchIndex = index

aa('init', {
Expand All @@ -37,6 +38,7 @@ const createAlgoliaClient = (config: AlgoliaConfig) => {
searchClient = {
...algoliaClient,
...customOptions,
instantSearchConfigs,
search(requests: MultipleQueriesQuery[]) {
if (requests.every(({ params }) => !params?.query)) return
return algoliaClient.search(requests)
Expand Down

0 comments on commit 4f4cb99

Please sign in to comment.