fix(SW-1168) Show only hotel cards that are visible on map

This commit is contained in:
Pontus Dreij
2024-12-12 10:04:16 +01:00
parent f5fb64729c
commit c3e56d5b49
6 changed files with 211 additions and 119 deletions
@@ -0,0 +1,29 @@
import type { HotelData } from "@/types/components/hotelReservation/selectHotel/hotelCardListingProps"
import type { HotelPin } from "@/types/components/hotelReservation/selectHotel/map"
export function getVisibleHotelPins(
map: google.maps.Map | null,
filteredHotelPins: HotelPin[]
) {
if (!map || !filteredHotelPins) return []
const bounds = map.getBounds()
if (!bounds) return []
return filteredHotelPins.filter((pin: any) => {
const { lat, lng } = pin.coordinates
return bounds.contains({ lat, lng })
})
}
export function getVisibleHotels(
hotels: HotelData[],
filteredHotelPins: HotelPin[],
map: google.maps.Map | null
) {
const visibleHotelPins = getVisibleHotelPins(map, filteredHotelPins)
const visibleHotels = hotels.filter((hotel: any) =>
visibleHotelPins.some((pin: any) => pin.operaId === hotel.hotelData.operaId)
)
return visibleHotels
}