fix(SW-2933): Making the hotels/city listing render correct for SEO purposes
Approved-by: Matilda Landström
This commit is contained in:
@@ -29,15 +29,38 @@ export function createDestinationDataStore({
|
||||
allHotels,
|
||||
pathname,
|
||||
sortItems,
|
||||
searchParams,
|
||||
}: InitialState) {
|
||||
const defaultSort =
|
||||
sortItems.find((s) => s.isDefault)?.value ?? sortItems[0].value
|
||||
|
||||
const allFilters = getFiltersFromHotels(allHotels)
|
||||
const allFilterSlugs = Object.values(allFilters).flatMap((filter: Filter[]) =>
|
||||
filter.map((f) => f.slug)
|
||||
)
|
||||
|
||||
const activeFilters: string[] = []
|
||||
const basePathnameWithoutFilters = getBasePathNameWithoutFilters(
|
||||
pathname,
|
||||
allFilterSlugs
|
||||
)
|
||||
if (basePathnameWithoutFilters !== pathname) {
|
||||
const pathParts = pathname.split("/")
|
||||
const lastPathPart = pathParts[pathParts.length - 1]
|
||||
activeFilters.push(lastPathPart)
|
||||
}
|
||||
|
||||
let activeSort = defaultSort
|
||||
if (searchParams) {
|
||||
const sortParam = searchParams.get("sort")
|
||||
if (sortParam && isValidSortOption(sortParam, sortItems)) {
|
||||
activeSort = sortParam
|
||||
}
|
||||
}
|
||||
const filteredHotels = getFilteredHotels(allHotels, activeFilters)
|
||||
const activeHotels = getSortedHotels(filteredHotels, activeSort)
|
||||
const filteredCities = getFilteredCities(filteredHotels, allCities)
|
||||
const activeCities = getSortedCities(filteredCities, activeSort)
|
||||
|
||||
return create<DestinationDataState>((set) => ({
|
||||
actions: {
|
||||
updateActiveFiltersAndSort(filters, sort) {
|
||||
@@ -144,24 +167,21 @@ export function createDestinationDataStore({
|
||||
},
|
||||
},
|
||||
allHotels,
|
||||
activeHotels: allHotels,
|
||||
pendingHotelCount: allHotels.length,
|
||||
activeHotels: activeHotels,
|
||||
pendingHotelCount: activeHotels.length,
|
||||
allCities,
|
||||
activeCities: allCities,
|
||||
pendingCityCount: allCities.length,
|
||||
activeSort: defaultSort,
|
||||
pendingSort: defaultSort,
|
||||
activeCities: activeCities,
|
||||
pendingCityCount: activeCities.length,
|
||||
activeSort,
|
||||
pendingSort: activeSort,
|
||||
defaultSort,
|
||||
activeFilters: [],
|
||||
pendingFilters: [],
|
||||
activeFilters,
|
||||
pendingFilters: activeFilters,
|
||||
allFilters,
|
||||
allFilterSlugs,
|
||||
basePathnameWithoutFilters: getBasePathNameWithoutFilters(
|
||||
pathname,
|
||||
allFilterSlugs
|
||||
),
|
||||
basePathnameWithoutFilters,
|
||||
sortItems,
|
||||
isLoading: true,
|
||||
isLoading: false,
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user