Files
web/apps/scandic-web/providers/DestinationDataProvider/index.tsx
Erik Tiekstra bee6c6d83a 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
2025-02-28 06:30:16 +00:00

40 lines
1.0 KiB
TypeScript

"use client"
import { usePathname } from "next/navigation"
import { useRef } from "react"
import { createDestinationDataStore } from "@/stores/destination-data"
import { DestinationDataContext } from "@/contexts/DestinationData"
import DestinationDataProviderContent from "./Content"
import type { DestinationDataStore } from "@/types/contexts/destination-data"
import type { DestinationDataProviderProps } from "@/types/providers/destination-data"
export default function DestinationDataProvider({
allCities = [],
allHotels,
sortItems,
children,
}: DestinationDataProviderProps) {
const storeRef = useRef<DestinationDataStore>()
const pathname = usePathname()
if (!storeRef.current) {
storeRef.current = createDestinationDataStore({
allCities,
allHotels,
pathname,
sortItems,
})
}
return (
<DestinationDataContext.Provider value={storeRef.current}>
<DestinationDataProviderContent>
{children}
</DestinationDataProviderContent>
</DestinationDataContext.Provider>
)
}