Merged in fix/SW-2457-destination-page-search-for-countries (pull request #1873)
* fix: able to search for countries on destinationpage * fix: filter out only desired types when using autocomplete Approved-by: Linus Flood
This commit is contained in:
@@ -31,6 +31,7 @@ export default function SearchList({
|
||||
isOpen,
|
||||
search,
|
||||
searchHistory,
|
||||
includeTypes,
|
||||
}: SearchListProps) {
|
||||
const lang = useLang()
|
||||
const intl = useIntl()
|
||||
@@ -53,10 +54,14 @@ export default function SearchList({
|
||||
isPending,
|
||||
isError,
|
||||
} = trpc.autocomplete.destinations.useQuery(
|
||||
{ query: debouncedSearch, lang },
|
||||
{ query: debouncedSearch, lang, includeTypes },
|
||||
{ enabled: autocompleteQueryEnabled }
|
||||
)
|
||||
|
||||
const typeFilteredSearchHistory = searchHistory?.filter((item) => {
|
||||
return includeTypes.includes(item.type)
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
clearErrors(searchInputName)
|
||||
}, [search, clearErrors, searchInputName])
|
||||
@@ -159,7 +164,7 @@ export default function SearchList({
|
||||
"We couldn't find a matching location for your search.",
|
||||
})}
|
||||
</Body>
|
||||
{searchHistory && searchHistory.length > 0 && (
|
||||
{typeFilteredSearchHistory && typeFilteredSearchHistory.length > 0 && (
|
||||
<>
|
||||
<Divider className={styles.noResultsDivider} color="beige" />
|
||||
<Footnote
|
||||
@@ -174,7 +179,7 @@ export default function SearchList({
|
||||
<List
|
||||
getItemProps={getItemProps}
|
||||
highlightedIndex={highlightedIndex}
|
||||
locations={searchHistory}
|
||||
locations={typeFilteredSearchHistory}
|
||||
/>
|
||||
|
||||
<Divider className={styles.divider} color="beige" />
|
||||
@@ -182,7 +187,7 @@ export default function SearchList({
|
||||
getItemProps={getItemProps}
|
||||
handleClearSearchHistory={handleClearSearchHistory}
|
||||
highlightedIndex={highlightedIndex}
|
||||
index={searchHistory.length}
|
||||
index={typeFilteredSearchHistory.length}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
@@ -190,7 +195,8 @@ export default function SearchList({
|
||||
)
|
||||
}
|
||||
|
||||
const displaySearchHistory = !debouncedSearch && searchHistory?.length
|
||||
const displaySearchHistory =
|
||||
!debouncedSearch && typeFilteredSearchHistory?.length
|
||||
if (displaySearchHistory) {
|
||||
return (
|
||||
<Dialog getMenuProps={getMenuProps}>
|
||||
@@ -202,14 +208,14 @@ export default function SearchList({
|
||||
<List
|
||||
getItemProps={getItemProps}
|
||||
highlightedIndex={highlightedIndex}
|
||||
locations={searchHistory}
|
||||
locations={typeFilteredSearchHistory}
|
||||
/>
|
||||
<Divider className={styles.divider} color="beige" />
|
||||
<ClearSearchButton
|
||||
getItemProps={getItemProps}
|
||||
handleClearSearchHistory={handleClearSearchHistory}
|
||||
highlightedIndex={highlightedIndex}
|
||||
index={searchHistory.length}
|
||||
index={typeFilteredSearchHistory.length}
|
||||
/>
|
||||
</Dialog>
|
||||
)
|
||||
@@ -224,6 +230,15 @@ export default function SearchList({
|
||||
<List
|
||||
getItemProps={getItemProps}
|
||||
highlightedIndex={highlightedIndex}
|
||||
label={intl.formatMessage({
|
||||
defaultMessage: "Countries",
|
||||
})}
|
||||
locations={autocompleteData?.hits.countries ?? []}
|
||||
/>
|
||||
<List
|
||||
getItemProps={getItemProps}
|
||||
highlightedIndex={highlightedIndex}
|
||||
initialIndex={autocompleteData?.hits.countries.length ?? 0}
|
||||
label={intl.formatMessage({
|
||||
defaultMessage: "Cities",
|
||||
})}
|
||||
@@ -232,7 +247,10 @@ export default function SearchList({
|
||||
<List
|
||||
getItemProps={getItemProps}
|
||||
highlightedIndex={highlightedIndex}
|
||||
initialIndex={autocompleteData?.hits.cities.length}
|
||||
initialIndex={
|
||||
(autocompleteData?.hits.countries.length ?? 0) +
|
||||
(autocompleteData?.hits.cities.length ?? 0)
|
||||
}
|
||||
label={intl.formatMessage({
|
||||
defaultMessage: "Hotels",
|
||||
})}
|
||||
|
||||
@@ -28,6 +28,7 @@ interface SearchProps {
|
||||
variant?: "rounded" | "default"
|
||||
withSearchButton?: boolean
|
||||
selectOnBlur?: boolean
|
||||
includeTypes: ("cities" | "hotels" | "countries")[]
|
||||
}
|
||||
|
||||
export function Search({
|
||||
@@ -37,6 +38,7 @@ export function Search({
|
||||
variant,
|
||||
withSearchButton = false,
|
||||
selectOnBlur = false,
|
||||
includeTypes,
|
||||
}: SearchProps) {
|
||||
const { register, setValue, setFocus } = useFormContext()
|
||||
const intl = useIntl()
|
||||
@@ -205,6 +207,7 @@ export function Search({
|
||||
search={searchTerm}
|
||||
searchHistory={searchHistory}
|
||||
searchInputName={SEARCH_TERM_NAME}
|
||||
includeTypes={includeTypes}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -45,6 +45,7 @@ export default function FormContent({
|
||||
handlePressEnter={onSubmit}
|
||||
selectOnBlur={true}
|
||||
inputName="search"
|
||||
includeTypes={["cities", "hotels"]}
|
||||
/>
|
||||
</div>
|
||||
<div className={styles.when}>
|
||||
|
||||
Reference in New Issue
Block a user