Feature/autocomplete search * wip autocomplete search * add skeletons to loading * Using aumlauts/accents when searching will still give results remove unused reducer sort autocomplete results * remove testcode * Add tests for autocomplete * cleanup tests * use node@20 * use node 22 * use node22 * merge fix: search button outside of viewport * merge * remove more unused code * fix: error message when empty search field in booking widget * fix: don't display empty white box when search field is empty and no searchHistory is present * merge * fix: set height of shimmer for search skeleton * rename autocomplete trpc -> destinationsAutocomplete * more accute cache key naming * fix: able to control wether bookingwidget is visible on startPage fix: sticky booking widget under alert * remove unused code * fix: skeletons fix: error overlay on search startpage * remove extra .nvmrc * merge Approved-by: Linus Flood
38 lines
962 B
TypeScript
38 lines
962 B
TypeScript
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 additionalTokens: string[] = []
|
|
|
|
tokens.forEach((token) => {
|
|
const replaced = token
|
|
.replace(/å/g, "a")
|
|
.replace(/ä/g, "a")
|
|
.replace(/ö/g, "o")
|
|
.replace(/æ/g, "a")
|
|
.replace(/ø/g, "o")
|
|
.replace(/é/g, "e")
|
|
.replace(/ü/g, "u")
|
|
if (replaced !== token) {
|
|
additionalTokens.push(replaced)
|
|
}
|
|
})
|
|
|
|
const allTokens = [...new Set([...tokens, ...additionalTokens])]
|
|
|
|
return allTokens
|
|
}
|
|
|
|
function hasValue(value: string | null | undefined): value is string {
|
|
return !!value && value.length > 0
|
|
}
|