* 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
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
"use client"
|
|
import { useSearchParams } from "next/navigation"
|
|
import { useRef } from "react"
|
|
|
|
import { createHotelListingDataStore } from "@/stores/hotel-listing-data"
|
|
|
|
import { HotelListingDataContext } from "@/contexts/HotelListingData"
|
|
|
|
import HotelListingDataProviderContent from "./Content"
|
|
|
|
import type { HotelListingDataStore } from "@/types/contexts/hotel-listing-data"
|
|
import type { HotelListingDataProviderProps } from "@/types/providers/hotel-listing-data"
|
|
|
|
export default function HotelListingDataProvider({
|
|
allHotels,
|
|
allFilters,
|
|
sortItems,
|
|
children,
|
|
}: HotelListingDataProviderProps) {
|
|
const storeRef = useRef<HotelListingDataStore>(undefined)
|
|
const searchParams = useSearchParams()
|
|
|
|
if (!storeRef.current) {
|
|
storeRef.current = createHotelListingDataStore({
|
|
allHotels,
|
|
allFilters,
|
|
sortItems,
|
|
searchParams,
|
|
})
|
|
}
|
|
|
|
return (
|
|
<HotelListingDataContext.Provider value={storeRef.current}>
|
|
<HotelListingDataProviderContent>
|
|
{children}
|
|
</HotelListingDataProviderContent>
|
|
</HotelListingDataContext.Provider>
|
|
)
|
|
}
|