Merged in feat/SW-1451-country-page-sorting (pull request #1426)

Feat/SW-1451 country page filtering and sorting

* feat(SW-1451): implemented sorting and filtering on country pages

* feat(SW-1451): Renamed hotel-data to destination-data because of its multi-purpose use

* feat(SW-1451): Now filtering after change of url instead of inside the store after submit


Approved-by: Fredrik Thorsson
This commit is contained in:
Erik Tiekstra
2025-02-28 06:30:16 +00:00
parent 747201b0f7
commit bee6c6d83a
69 changed files with 1124 additions and 531 deletions

View File

@@ -1,8 +1,9 @@
import type { SortOption } from "../enums/hotelFilterAndSort"
import type { SortOption } from "../enums/destinationFilterAndSort"
export interface SortItem {
label: string
value: SortOption
isDefault?: boolean
}
export interface Filter {

View File

@@ -0,0 +1,3 @@
import type { createDestinationDataStore } from "@/stores/destination-data"
export type DestinationDataStore = ReturnType<typeof createDestinationDataStore>

View File

@@ -1,3 +0,0 @@
import type { createHotelDataStore } from "@/stores/hotel-data"
export type HotelDataStore = ReturnType<typeof createHotelDataStore>

View File

@@ -1,4 +1,5 @@
export enum SortOption {
Recommended = "recommended",
Distance = "distance",
Name = "name",
TripAdvisorRating = "tripadvisor",

View File

@@ -0,0 +1,9 @@
import type { HotelDataWithUrl } from "@/types/hotel"
import type { SortItem } from "../components/destinationFilterAndSort"
import type { DestinationCityListItem } from "../trpc/routers/contentstack/destinationCityPage"
export interface DestinationDataProviderProps extends React.PropsWithChildren {
allHotels: HotelDataWithUrl[]
allCities?: DestinationCityListItem[]
sortItems: SortItem[]
}

View File

@@ -1,8 +0,0 @@
import type { HotelDataWithUrl } from "@/types/hotel"
import type { SortItem } from "../components/hotelFilterAndSort"
export interface HotelDataProviderProps extends React.PropsWithChildren {
allHotels: HotelDataWithUrl[]
filterFromUrl?: string
sortItems: SortItem[]
}

View File

@@ -1,46 +1,47 @@
import type { ReadonlyURLSearchParams } from "next/navigation"
import type {
CategorizedFilters,
SortItem,
} from "../components/hotelFilterAndSort"
import type { SortOption } from "../enums/hotelFilterAndSort"
} from "../components/destinationFilterAndSort"
import type { SortOption } from "../enums/destinationFilterAndSort"
import type { HotelDataWithUrl } from "../hotel"
import type { DestinationCityListItem } from "../trpc/routers/contentstack/destinationCityPage"
interface Actions {
submitFiltersAndSort: () => void
updateActiveFiltersAndSort: (filters: string[], sort: string | null) => void
setPendingSort: (sort: SortOption) => void
togglePendingFilter: (filter: string) => void
clearPendingFilters: () => void
resetPendingValues: () => void
loadInitialHashFilter: (hash: string) => void
setIsLoading: (isLoading: boolean) => void
}
export interface SubmitCallbackData {
sort: SortOption
defaultSort: SortOption
filters: string[]
basePath: string
}
export interface HotelDataState {
export interface DestinationDataState {
actions: Actions
allCities: DestinationCityListItem[]
activeCities: DestinationCityListItem[]
allHotels: HotelDataWithUrl[]
activeHotels: HotelDataWithUrl[]
pendingSort: SortOption
activeSort: SortOption
defaultSort: SortOption
pendingFilters: string[]
activeFilters: string[]
pendingCount: number
searchParams: ReadonlyURLSearchParams
pendingHotelCount: number
pendingCityCount: number
allFilters: CategorizedFilters
allFilterSlugs: string[]
basePathnameWithoutFilters: string
sortItems: SortItem[]
initialHashFilterLoaded: boolean
isLoading: boolean
}
export interface InitialState
extends Pick<HotelDataState, "allHotels" | "searchParams" | "sortItems"> {
extends Pick<DestinationDataState, "allHotels" | "allCities" | "sortItems"> {
pathname: string
filterFromUrl?: string
submitCallbackFn?: (data: SubmitCallbackData) => void
}