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 { useMap } from "@vis.gl/react-google-maps"
import { useCallback, useEffect, useMemo, useRef, useState } from "react" import { useCallback, useEffect, useMemo, useRef, useState } from "react"
import { useIntl } from "react-intl" 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 { HotelData } from "@/types/components/hotelReservation/selectHotel/hotelCardListingProps"
import type { SelectHotelMapProps } from "@/types/components/hotelReservation/selectHotel/map" import type { SelectHotelMapProps } from "@/types/components/hotelReservation/selectHotel/map"
const SKELETON_LOAD_DELAY = 750
export default function SelectHotelContent({ export default function SelectHotelContent({
hotelPins, hotelPins,
cityCoordinates, cityCoordinates,
@@ -39,7 +42,7 @@ export default function SelectHotelContent({
const isAboveMobile = useMediaQuery("(min-width: 768px)") const isAboveMobile = useMediaQuery("(min-width: 768px)")
const [visibleHotels, setVisibleHotels] = useState<HotelData[]>([]) const [visibleHotels, setVisibleHotels] = useState<HotelData[]>([])
const [showBackToTop, setShowBackToTop] = useState<boolean>(false) 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 listingContainerRef = useRef<HTMLDivElement | null>(null)
const activeFilters = useHotelFilterStore((state) => state.activeFilters) const activeFilters = useHotelFilterStore((state) => state.activeFilters)
@@ -99,15 +102,21 @@ export default function SelectHotelContent({
const visibleHotels = getVisibleHotels(hotels, filteredHotelPins, map) const visibleHotels = getVisibleHotels(hotels, filteredHotelPins, map)
setVisibleHotels(visibleHotels) setVisibleHotels(visibleHotels)
setTimeout(() => { setTimeout(() => {
setIsMapLoaded(true) setShowSkeleton(true)
}, 750) }, SKELETON_LOAD_DELAY)
}, [hotels, filteredHotelPins, map]) }, [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( const debouncedUpdateHotelCards = useMemo(
() => () =>
debounce(() => { debounce(() => {
if (!map) return if (!map) return
setIsMapLoaded(false) setShowSkeleton(false)
getHotelCards() getHotelCards()
}, 100), }, 100),
[map, getHotelCards] [map, getHotelCards]
@@ -146,13 +155,13 @@ export default function SelectHotelContent({
</Button> </Button>
<FilterAndSortModal filters={filterList} /> <FilterAndSortModal filters={filterList} />
</div> </div>
{isMapLoaded ? ( {showSkeleton ? (
<HotelListing hotels={visibleHotels} />
) : (
<> <>
<RoomCardSkeleton /> <RoomCardSkeleton />
<RoomCardSkeleton /> <RoomCardSkeleton />
</> </>
) : (
<HotelListing hotels={visibleHotels} />
)} )}
{showBackToTop && ( {showBackToTop && (
<BackToTopButton position="left" onClick={scrollToTop} /> <BackToTopButton position="left" onClick={scrollToTop} />
@@ -163,7 +172,7 @@ export default function SelectHotelContent({
coordinates={coordinates} coordinates={coordinates}
hotelPins={filteredHotelPins} hotelPins={filteredHotelPins}
mapId={mapId} mapId={mapId}
onMapLoad={debouncedUpdateHotelCards} onTilesLoaded={debouncedUpdateHotelCards}
/> />
</div> </div>
) )

View File

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

View File

@@ -19,7 +19,7 @@ export default function InteractiveMap({
hotelPins, hotelPins,
mapId, mapId,
closeButton, closeButton,
onMapLoad, onTilesLoaded,
onActivePoiChange, onActivePoiChange,
}: InteractiveMapProps) { }: InteractiveMapProps) {
const intl = useIntl() const intl = useIntl()
@@ -48,7 +48,7 @@ export default function InteractiveMap({
return ( return (
<div className={styles.mapContainer}> <div className={styles.mapContainer}>
<Map {...mapOptions} onTilesLoaded={onMapLoad}> <Map {...mapOptions} onTilesLoaded={onTilesLoaded}>
{hotelPins && <HotelListingMapContent hotelPins={hotelPins} />} {hotelPins && <HotelListingMapContent hotelPins={hotelPins} />}
{pointsOfInterest && ( {pointsOfInterest && (
<HotelMapContent <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 { HotelPin } from "@/types/components/hotelReservation/selectHotel/map"
import type { Coordinates } from "@/types/components/maps/coordinates" import type { Coordinates } from "@/types/components/maps/coordinates"
@@ -11,6 +11,6 @@ export interface InteractiveMapProps {
hotelPins?: HotelPin[] hotelPins?: HotelPin[]
mapId: string mapId: string
closeButton: ReactElement closeButton: ReactElement
onMapLoad?: () => void onTilesLoaded?: () => void
onActivePoiChange?: (poi: PointOfInterest["name"] | null) => void onActivePoiChange?: (poi: PointOfInterest["name"] | null) => void
} }