Skip to content

Commit

Permalink
Hotfix advanced search filters not working (#11554)
Browse files Browse the repository at this point in the history
  • Loading branch information
DejayJD authored Mar 8, 2025
1 parent 3abf343 commit 2b2b1db
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions packages/web/src/components/search-bar/DesktopSearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type { InputRef } from 'antd/lib/input'
import cn from 'classnames'
import { Link, useHistory, useLocation, matchPath } from 'react-router-dom'
import { useSearchParams } from 'react-router-dom-v5-compat'
import { useDebounce } from 'react-use'
import { useDebounce, usePrevious } from 'react-use'

import { searchResultsPage } from 'utils/route'

Expand Down Expand Up @@ -93,16 +93,20 @@ export const DesktopSearchBar = () => {
{ query: debouncedValue, limit: DEFAULT_LIMIT },
{ enabled: !isSearchPage }
)

const previousDebouncedValue = usePrevious(debouncedValue)
useEffect(() => {
if (isSearchPage) {
if (debouncedValue) {
setSearchParams({ query: debouncedValue })
} else {
setSearchParams({})
}
if (isSearchPage && debouncedValue !== previousDebouncedValue) {
const newParams = new URLSearchParams(searchParams)
newParams.set('query', debouncedValue)
setSearchParams(newParams)
}
}, [debouncedValue, isSearchPage, setSearchParams])
}, [
debouncedValue,
isSearchPage,
setSearchParams,
previousDebouncedValue,
searchParams
])

const handleSearch = useCallback((value: string) => {
setInputValue(value)
Expand All @@ -120,13 +124,22 @@ export const DesktopSearchBar = () => {
(event: React.KeyboardEvent<HTMLInputElement>) => {
if (event.key === 'Enter') {
if (isSearchPage) {
setSearchParams({ query: inputValue })
const newParams = new URLSearchParams(searchParams)
newParams.set('query', debouncedValue)
setSearchParams(newParams)
} else {
history.push(searchResultsPage('all', inputValue))
}
}
},
[history, inputValue, isSearchPage, setSearchParams]
[
debouncedValue,
history,
inputValue,
isSearchPage,
searchParams,
setSearchParams
]
)

const renderSuffix = () => {
Expand Down

0 comments on commit 2b2b1db

Please sign in to comment.