fix(SW-1111) added filter on pins

This commit is contained in:
Pontus Dreij
2024-12-06 08:40:26 +01:00
parent 69fa5b9b31
commit 007b77101b
3 changed files with 18 additions and 2 deletions

View File

@@ -28,5 +28,8 @@ export function getHotelPins(hotels: HotelData[]): HotelPin[] {
.slice(0, 3), .slice(0, 3),
ratings: hotel.hotelData.ratings?.tripAdvisor.rating ?? null, ratings: hotel.hotelData.ratings?.tripAdvisor.rating ?? null,
operaId: hotel.hotelData.operaId, operaId: hotel.hotelData.operaId,
facilityIds: hotel.hotelData.detailedFacilities.map(
(facility) => facility.id
),
})) }))
} }

View File

@@ -1,11 +1,12 @@
"use client" "use client"
import { APIProvider } from "@vis.gl/react-google-maps" import { APIProvider } from "@vis.gl/react-google-maps"
import { useSearchParams } from "next/navigation" import { useSearchParams } from "next/navigation"
import { useEffect, useRef, useState } from "react" import { useEffect, useMemo, useRef, useState } from "react"
import { useIntl } from "react-intl" import { useIntl } from "react-intl"
import { useMediaQuery } from "usehooks-ts" import { useMediaQuery } from "usehooks-ts"
import { selectHotel } from "@/constants/routes/hotelReservation" import { selectHotel } from "@/constants/routes/hotelReservation"
import { useHotelFilterStore } from "@/stores/hotel-filters"
import { CloseIcon, CloseLargeIcon } from "@/components/Icons" import { CloseIcon, CloseLargeIcon } from "@/components/Icons"
import InteractiveMap from "@/components/Maps/InteractiveMap" import InteractiveMap from "@/components/Maps/InteractiveMap"
@@ -37,6 +38,7 @@ export default function SelectHotelMap({
const [activeHotelPin, setActiveHotelPin] = useState<string | null>(null) const [activeHotelPin, setActiveHotelPin] = useState<string | null>(null)
const [showBackToTop, setShowBackToTop] = useState<boolean>(false) const [showBackToTop, setShowBackToTop] = useState<boolean>(false)
const listingContainerRef = useRef<HTMLDivElement | null>(null) const listingContainerRef = useRef<HTMLDivElement | null>(null)
const activeFilters = useHotelFilterStore((state) => state.activeFilters)
const selectHotelParams = new URLSearchParams(searchParams.toString()) const selectHotelParams = new URLSearchParams(searchParams.toString())
const selectedHotel = selectHotelParams.get("selectedHotel") const selectedHotel = selectHotelParams.get("selectedHotel")
@@ -83,6 +85,16 @@ export default function SelectHotelMap({
hotelListingElement?.scrollTo({ top: 0, behavior: "smooth" }) hotelListingElement?.scrollTo({ top: 0, behavior: "smooth" })
} }
const filteredHotelPins = useMemo(
() =>
hotelPins.filter((hotel) =>
activeFilters.every((filterId) =>
hotel.facilityIds.includes(Number(filterId))
)
),
[activeFilters, hotelPins]
)
const closeButton = ( const closeButton = (
<Button <Button
intent="inverted" intent="inverted"
@@ -128,7 +140,7 @@ export default function SelectHotelMap({
<InteractiveMap <InteractiveMap
closeButton={closeButton} closeButton={closeButton}
coordinates={coordinates} coordinates={coordinates}
hotelPins={hotelPins} hotelPins={filteredHotelPins}
activeHotelPin={activeHotelPin} activeHotelPin={activeHotelPin}
onActiveHotelPinChange={setActiveHotelPin} onActiveHotelPinChange={setActiveHotelPin}
mapId={mapId} mapId={mapId}

View File

@@ -41,6 +41,7 @@ export type HotelPin = {
amenities: Filter[] amenities: Filter[]
ratings: number | null ratings: number | null
operaId: string operaId: string
facilityIds: number[]
} }
export interface HotelListingMapContentProps { export interface HotelListingMapContentProps {