Consolidate autocomplete search SW-2253 SW-2338 * use fuse.js for fuzzy search * Handle weird behaviour when search field loses focus on destinationPage * Add error logging for JumpTo when no URL was provided * Switch to use <Typography /> over <Caption /> * fix: bookingWidget search label should always be red * fix: searchHistory can no longer add invalid items * fix: list more hits when searching * fix: issue when searchField value was undefined * fix: don't show searchHistory label if no searchHistory items * simplify skeleton for listitems in search Approved-by: Linus Flood
23 lines
644 B
TypeScript
23 lines
644 B
TypeScript
import { normalizeAumlauts } from "./normalizeAumlauts"
|
|
|
|
import type { Location } from "@/types/trpc/routers/hotel/locations"
|
|
|
|
export function getSearchTokens(location: Location) {
|
|
const tokens = [
|
|
...(location.keyWords?.map((x) => x.toLocaleLowerCase()) ?? []),
|
|
location.name,
|
|
location.type === "hotels"
|
|
? location.relationships.city.name
|
|
: location.country,
|
|
]
|
|
.filter(hasValue)
|
|
.map((x) => x.toLocaleLowerCase())
|
|
|
|
const normalizedTokens = normalizeAumlauts(tokens)
|
|
return normalizedTokens
|
|
}
|
|
|
|
function hasValue(value: string | null | undefined): value is string {
|
|
return !!value && value.length > 0
|
|
}
|