feat/sw-251 Filter hotels on select hotel page

This commit is contained in:
Niclas Edenvin
2024-11-06 15:22:02 +01:00
parent 560fb25aee
commit a8558eb499
5 changed files with 124 additions and 20 deletions

View File

@@ -1,3 +1,7 @@
"use client"
import { useSearchParams } from "next/navigation"
import { useMemo } from "react"
import Title from "@/components/TempDesignSystem/Text/Title"
import HotelCard from "../HotelCard"
@@ -7,12 +11,25 @@ import styles from "./hotelCardListing.module.css"
import { HotelCardListingProps } from "@/types/components/hotelReservation/selectHotel/hotelCardListingProps"
export default function HotelCardListing({ hotelData }: HotelCardListingProps) {
// TODO: filter with url params
const searchParams = useSearchParams()
const hotels = useMemo(() => {
const appliedFilters = searchParams.get("filters")?.split(",")
if (!appliedFilters || appliedFilters.length === 0) return hotelData
return hotelData.filter((hotel) =>
appliedFilters.every((appliedFilterId) =>
hotel.hotelData.detailedFacilities.some(
(facility) => facility.id.toString() === appliedFilterId
)
)
)
}, [searchParams, hotelData])
return (
<section className={styles.hotelCards}>
{hotelData && hotelData.length ? (
hotelData.map((hotel) => (
{hotels.length ? (
hotels.map((hotel) => (
<HotelCard key={hotel.hotelData.name} hotel={hotel} />
))
) : (