Files
web/apps/scandic-web/providers/HotelListingDataProvider/index.tsx
Erik Tiekstra fa7214cb58 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
2025-07-04 09:27:20 +00:00

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>
)
}