diff --git a/apps/scandic-web/components/Blocks/CampaignHotelListing/Provider/Content.tsx b/apps/scandic-web/components/Blocks/CampaignHotelListing/Provider/Content.tsx deleted file mode 100644 index 7cba6b81c..000000000 --- a/apps/scandic-web/components/Blocks/CampaignHotelListing/Provider/Content.tsx +++ /dev/null @@ -1,41 +0,0 @@ -"use client" - -import { useParams } from "next/navigation" -import { useEffect } from "react" - -import { useDestinationDataStore } from "@/stores/destination-data" - -export default function DestinationDataProviderContent({ - children, -}: React.PropsWithChildren) { - const params = useParams() - const { basePath, updateActiveFiltersAndSort } = useDestinationDataStore( - (state) => ({ - basePath: state.basePathnameWithoutFilters, - updateActiveFiltersAndSort: state.actions.updateActiveFiltersAndSort, - }) - ) - - useEffect(() => { - const currentUrl = new URL(window.location.href) - const searchParams = currentUrl.searchParams - const currentPathname = currentUrl.pathname - const currentHash = currentUrl.hash - const sort = searchParams.get("sort") - const filters = [] - const pathParts = currentPathname.split("/") - const lastPathPart = pathParts[pathParts.length - 1] - - if (basePath !== currentPathname) { - filters.push(lastPathPart) - } - if (currentHash) { - const hashValue = currentHash.substring(1) - filters.push(...hashValue.split("&")) - } - - updateActiveFiltersAndSort(filters, sort) - }, [params, updateActiveFiltersAndSort, basePath]) - - return <>{children} -} diff --git a/apps/scandic-web/components/Blocks/CampaignHotelListing/Provider/index.tsx b/apps/scandic-web/components/Blocks/CampaignHotelListing/Provider/index.tsx deleted file mode 100644 index 583833c44..000000000 --- a/apps/scandic-web/components/Blocks/CampaignHotelListing/Provider/index.tsx +++ /dev/null @@ -1,45 +0,0 @@ -"use client" -import { useSearchParams } 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, - allFilters, - filterFromUrl, - sortItems, - pathname, - children, -}: DestinationDataProviderProps) { - const storeRef = useRef(undefined) - const searchParams = useSearchParams() - - if (!storeRef.current) { - storeRef.current = createDestinationDataStore({ - allCities, - allHotels, - allFilters, - filterFromUrl, - pathname, - sortItems, - searchParams, - }) - } - - return ( - - - {children} - - - ) -} diff --git a/apps/scandic-web/components/DestinationFilterAndSort/index.tsx b/apps/scandic-web/components/DestinationFilterAndSort/index.tsx index 5aaa1c045..d45247283 100644 --- a/apps/scandic-web/components/DestinationFilterAndSort/index.tsx +++ b/apps/scandic-web/components/DestinationFilterAndSort/index.tsx @@ -99,9 +99,9 @@ export default function DestinationFilterAndSort({ parsedUrl.pathname += `/${firstFilter}` } if (remainingFilters.length > 0) { - parsedUrl.hash = `#${remainingFilters.join("&")}` + searchParams.set("filter", remainingFilters.join("&")) } else { - parsedUrl.hash = "" + searchParams.delete("filter") } router.push(parsedUrl.toString(), { scroll: false }) diff --git a/apps/scandic-web/providers/DestinationDataProvider/Content.tsx b/apps/scandic-web/providers/DestinationDataProvider/Content.tsx index 7cba6b81c..2946a6077 100644 --- a/apps/scandic-web/providers/DestinationDataProvider/Content.tsx +++ b/apps/scandic-web/providers/DestinationDataProvider/Content.tsx @@ -20,8 +20,8 @@ export default function DestinationDataProviderContent({ const currentUrl = new URL(window.location.href) const searchParams = currentUrl.searchParams const currentPathname = currentUrl.pathname - const currentHash = currentUrl.hash const sort = searchParams.get("sort") + const filterParam = searchParams.get("filter") const filters = [] const pathParts = currentPathname.split("/") const lastPathPart = pathParts[pathParts.length - 1] @@ -29,9 +29,8 @@ export default function DestinationDataProviderContent({ if (basePath !== currentPathname) { filters.push(lastPathPart) } - if (currentHash) { - const hashValue = currentHash.substring(1) - filters.push(...hashValue.split("&")) + if (filterParam) { + filters.push(...filterParam.split("&")) } updateActiveFiltersAndSort(filters, sort)