fix(SW-1168) Fixed comments for map

This commit is contained in:
Pontus Dreij
2024-12-12 20:30:41 +01:00
parent e05372f4d8
commit e1bc7c25e0
4 changed files with 23 additions and 14 deletions

View File

@@ -1,3 +1,4 @@
"use client"
import { useMap } from "@vis.gl/react-google-maps"
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
import { useIntl } from "react-intl"
@@ -25,6 +26,8 @@ import styles from "./selectHotelMapContent.module.css"
import type { HotelData } from "@/types/components/hotelReservation/selectHotel/hotelCardListingProps"
import type { SelectHotelMapProps } from "@/types/components/hotelReservation/selectHotel/map"
const SKELETON_LOAD_DELAY = 750
export default function SelectHotelContent({
hotelPins,
cityCoordinates,
@@ -39,7 +42,7 @@ export default function SelectHotelContent({
const isAboveMobile = useMediaQuery("(min-width: 768px)")
const [visibleHotels, setVisibleHotels] = useState<HotelData[]>([])
const [showBackToTop, setShowBackToTop] = useState<boolean>(false)
const [isMapLoaded, setIsMapLoaded] = useState<boolean>(false)
const [showSkeleton, setShowSkeleton] = useState<boolean>(false)
const listingContainerRef = useRef<HTMLDivElement | null>(null)
const activeFilters = useHotelFilterStore((state) => state.activeFilters)
@@ -99,15 +102,21 @@ export default function SelectHotelContent({
const visibleHotels = getVisibleHotels(hotels, filteredHotelPins, map)
setVisibleHotels(visibleHotels)
setTimeout(() => {
setIsMapLoaded(true)
}, 750)
setShowSkeleton(true)
}, SKELETON_LOAD_DELAY)
}, [hotels, filteredHotelPins, map])
/**
* Updates visible hotels when map viewport changes (zoom/pan)
* - Debounces updates to prevent excessive re-renders during map interaction
* - Shows loading skeleton while map tiles load
* - Triggers on: initial load, zoom, pan, and tile loading completion
*/
const debouncedUpdateHotelCards = useMemo(
() =>
debounce(() => {
if (!map) return
setIsMapLoaded(false)
setShowSkeleton(false)
getHotelCards()
}, 100),
[map, getHotelCards]
@@ -146,13 +155,13 @@ export default function SelectHotelContent({
</Button>
<FilterAndSortModal filters={filterList} />
</div>
{isMapLoaded ? (
<HotelListing hotels={visibleHotels} />
) : (
{showSkeleton ? (
<>
<RoomCardSkeleton />
<RoomCardSkeleton />
</>
) : (
<HotelListing hotels={visibleHotels} />
)}
{showBackToTop && (
<BackToTopButton position="left" onClick={scrollToTop} />
@@ -163,7 +172,7 @@ export default function SelectHotelContent({
coordinates={coordinates}
hotelPins={filteredHotelPins}
mapId={mapId}
onMapLoad={debouncedUpdateHotelCards}
onTilesLoaded={debouncedUpdateHotelCards}
/>
</div>
)

View File

@@ -2,7 +2,7 @@
import { APIProvider } from "@vis.gl/react-google-maps"
import SelectHotelContent from "./SelectHotelMapContent"
import SelectHotelMapContent from "./SelectHotelMapContent"
import type { SelectHotelMapProps } from "@/types/components/hotelReservation/selectHotel/map"
@@ -16,7 +16,7 @@ export default function SelectHotelMap({
}: SelectHotelMapProps) {
return (
<APIProvider apiKey={apiKey}>
<SelectHotelContent
<SelectHotelMapContent
hotelPins={hotelPins}
cityCoordinates={cityCoordinates}
mapId={mapId}

View File

@@ -19,7 +19,7 @@ export default function InteractiveMap({
hotelPins,
mapId,
closeButton,
onMapLoad,
onTilesLoaded,
onActivePoiChange,
}: InteractiveMapProps) {
const intl = useIntl()
@@ -48,7 +48,7 @@ export default function InteractiveMap({
return (
<div className={styles.mapContainer}>
<Map {...mapOptions} onTilesLoaded={onMapLoad}>
<Map {...mapOptions} onTilesLoaded={onTilesLoaded}>
{hotelPins && <HotelListingMapContent hotelPins={hotelPins} />}
{pointsOfInterest && (
<HotelMapContent

View File

@@ -1,4 +1,4 @@
import { ReactElement } from "react"
import type { ReactElement } from "react"
import type { HotelPin } from "@/types/components/hotelReservation/selectHotel/map"
import type { Coordinates } from "@/types/components/maps/coordinates"
@@ -11,6 +11,6 @@ export interface InteractiveMapProps {
hotelPins?: HotelPin[]
mapId: string
closeButton: ReactElement
onMapLoad?: () => void
onTilesLoaded?: () => void
onActivePoiChange?: (poi: PointOfInterest["name"] | null) => void
}