Feat/SW-2271 hotel list filtering

* feat(SW-2271): Changes to hotel data types in preperation for filtering
* feat(SW-2271): Added filter and sort functionality

Approved-by: Matilda Landström
This commit is contained in:
Erik Tiekstra
2025-07-04 09:27:20 +00:00
parent 82e21af0d4
commit fa7214cb58
58 changed files with 1572 additions and 450 deletions

View File

@@ -1,17 +1,17 @@
import { SortOption } from "../enums/destinationFilterAndSort"
import { HotelSortOption } from "../types/hotel"
import type { DestinationCityListItem } from "../types/destinationCityPage"
const CITY_SORTING_STRATEGIES: Partial<
Record<
SortOption,
HotelSortOption,
(a: DestinationCityListItem, b: DestinationCityListItem) => number
>
> = {
[SortOption.Name]: function (a, b) {
[HotelSortOption.Name]: function (a, b) {
return a.cityName.localeCompare(b.cityName)
},
[SortOption.Recommended]: function (a, b) {
[HotelSortOption.Recommended]: function (a, b) {
if (a.sort_order === null && b.sort_order === null) {
return a.cityName.localeCompare(b.cityName)
}
@@ -27,7 +27,7 @@ const CITY_SORTING_STRATEGIES: Partial<
export function getSortedCities(
cities: DestinationCityListItem[],
sortOption: SortOption
sortOption: HotelSortOption
) {
const sortFn = CITY_SORTING_STRATEGIES[sortOption]
return sortFn ? cities.sort(sortFn) : cities