diff --git a/apps/scandic-web/components/HotelReservation/HotelCardListing/index.tsx b/apps/scandic-web/components/HotelReservation/HotelCardListing/index.tsx index b6fc1d9a9..377929e3b 100644 --- a/apps/scandic-web/components/HotelReservation/HotelCardListing/index.tsx +++ b/apps/scandic-web/components/HotelReservation/HotelCardListing/index.tsx @@ -28,6 +28,7 @@ import { BookingCodeFilterEnum } from "@/types/enums/bookingCodeFilter" export default function HotelCardListing({ hotelData, + unfilteredHotelCount, type = HotelCardListingTypeEnum.PageListing, }: HotelCardListingProps) { const { data: session } = useSession() @@ -104,8 +105,8 @@ export default function HotelCardListing({ }, [activeHotel, type]) useEffect(() => { - setResultCount(hotels.length) - }, [hotels, setResultCount]) + setResultCount(hotels.length, unfilteredHotelCount) + }, [hotels, setResultCount, unfilteredHotelCount]) function isHotelActiveInMapView(hotelName: string): boolean { return ( diff --git a/apps/scandic-web/components/HotelReservation/SelectHotel/FilterAndSortModal/filterAndSortModal.module.css b/apps/scandic-web/components/HotelReservation/SelectHotel/Filters/FilterAndSortModal/filterAndSortModal.module.css similarity index 100% rename from apps/scandic-web/components/HotelReservation/SelectHotel/FilterAndSortModal/filterAndSortModal.module.css rename to apps/scandic-web/components/HotelReservation/SelectHotel/Filters/FilterAndSortModal/filterAndSortModal.module.css diff --git a/apps/scandic-web/components/HotelReservation/SelectHotel/FilterAndSortModal/index.tsx b/apps/scandic-web/components/HotelReservation/SelectHotel/Filters/FilterAndSortModal/index.tsx similarity index 74% rename from apps/scandic-web/components/HotelReservation/SelectHotel/FilterAndSortModal/index.tsx rename to apps/scandic-web/components/HotelReservation/SelectHotel/Filters/FilterAndSortModal/index.tsx index 06fbd972e..03d207a2f 100644 --- a/apps/scandic-web/components/HotelReservation/SelectHotel/FilterAndSortModal/index.tsx +++ b/apps/scandic-web/components/HotelReservation/SelectHotel/Filters/FilterAndSortModal/index.tsx @@ -4,7 +4,7 @@ import { usePathname, useSearchParams, } from "next/dist/client/components/navigation" -import { useCallback, useState } from "react" +import { useCallback, useEffect, useState } from "react" import { Dialog as AriaDialog, DialogTrigger, @@ -24,8 +24,8 @@ import Footnote from "@/components/TempDesignSystem/Text/Footnote" import Subtitle from "@/components/TempDesignSystem/Text/Subtitle" import useInitializeFiltersFromUrl from "@/hooks/useInitializeFiltersFromUrl" -import HotelFilter from "../HotelFilter" -import { DEFAULT_SORT } from "../HotelSorter" +import { DEFAULT_SORT } from "../../HotelSorter" +import FilterContent from "../FilterContent" import styles from "./filterAndSortModal.module.css" @@ -40,14 +40,32 @@ export default function FilterAndSortModal({ setShowSkeleton, }: FilterAndSortModalProps) { const intl = useIntl() + useInitializeFiltersFromUrl() const searchParams = useSearchParams() const pathname = usePathname() - const resultCount = useHotelFilterStore((state) => state.resultCount) - const setFilters = useHotelFilterStore((state) => state.setFilters) - const activeFilters = useHotelFilterStore((state) => state.activeFilters) + + const { resultCount, setFilters, activeFilters, unfilteredResultCount } = + useHotelFilterStore((state) => ({ + resultCount: state.resultCount, + setFilters: state.setFilters, + activeFilters: state.activeFilters, + unfilteredResultCount: state.unfilteredResultCount, + })) + const [sort, setSort] = useState(searchParams.get("sort") ?? DEFAULT_SORT) + const [selectedFilters, setSelectedFilters] = + useState(activeFilters) + + const [filteredCount, setFilteredCount] = useState(resultCount) + + useEffect(() => { + if (activeFilters.length) { + setSelectedFilters(activeFilters) + } + }, [activeFilters]) + const sortItems: SortItem[] = [ { label: intl.formatMessage({ @@ -81,14 +99,21 @@ export default function FilterAndSortModal({ const handleApplyFiltersAndSorting = useCallback( (close: () => void) => { + setFilters(selectedFilters) + if (setShowSkeleton) { setShowSkeleton(true) } - if (sort === searchParams.get("sort")) { - close() - } const newSearchParams = new URLSearchParams(searchParams) + + const values = selectedFilters.join(",") + if (values === "") { + newSearchParams.delete("filters") + } else { + newSearchParams.set("filters", values) + } + newSearchParams.set("sort", sort) window.history.replaceState( @@ -103,7 +128,7 @@ export default function FilterAndSortModal({ }, 500) } }, - [pathname, searchParams, sort, setShowSkeleton] + [pathname, searchParams, sort, setShowSkeleton, selectedFilters, setFilters] ) return ( @@ -159,7 +184,19 @@ export default function FilterAndSortModal({
- + { + const isSelected = selectedFilters.includes(id) + setSelectedFilters((prev) => + isSelected + ? prev.filter((s) => s !== id) + : [...prev, id] + ) + }} + onFilteredCountChange={setFilteredCount} + />