Merged in fix/SW-1491-SW-1500-link-in-hotel-card-to-map (pull request #1707)
fix(SW-1491-SW-1500): address on hotel card should go to map, remove link on maplisting view * fix(SW-1491-SW-1500): address on hotel card should go to map, remove link on maplisting view * fix(SW-1491-SW-1500): fix comment * fix(SW-1491-SW-1500): add underscore Approved-by: Niclas Edenvin
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"use client"
|
||||
import { useSearchParams } from "next/navigation"
|
||||
import { useSession } from "next-auth/react"
|
||||
import { useEffect, useMemo } from "react"
|
||||
import { useEffect, useMemo, useRef } from "react"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { useBookingCodeFilterStore } from "@/stores/bookingCode-filter"
|
||||
@@ -39,6 +39,7 @@ export default function HotelCardListing({
|
||||
const intl = useIntl()
|
||||
const { activeHotelCard } = useHotelsMapStore()
|
||||
const { showBackToTop, scrollToTop } = useScrollToTop({ threshold: 490 })
|
||||
const activeCardRef = useRef<HTMLDivElement | null>(null)
|
||||
|
||||
const sortBy = searchParams.get("sort") ?? DEFAULT_SORT
|
||||
|
||||
@@ -99,25 +100,47 @@ export default function HotelCardListing({
|
||||
isSpecialRate,
|
||||
])
|
||||
|
||||
useEffect(() => {
|
||||
if (activeCardRef.current && type === HotelCardListingTypeEnum.MapListing) {
|
||||
activeCardRef.current.scrollIntoView({
|
||||
behavior: "smooth",
|
||||
block: "nearest",
|
||||
inline: "center",
|
||||
})
|
||||
}
|
||||
}, [activeHotelCard, type])
|
||||
|
||||
useEffect(() => {
|
||||
setResultCount(hotels.length)
|
||||
}, [hotels, setResultCount])
|
||||
|
||||
function isHotelActiveInMapView(hotelName: string): boolean {
|
||||
return (
|
||||
hotelName === activeHotelCard &&
|
||||
type === HotelCardListingTypeEnum.MapListing
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<section className={styles.hotelCards}>
|
||||
{hotels?.length
|
||||
? hotels.map((hotel) => (
|
||||
<div
|
||||
key={hotel.hotel.operaId}
|
||||
ref={
|
||||
isHotelActiveInMapView(hotel.hotel.name) ? activeCardRef : null
|
||||
}
|
||||
data-active={
|
||||
hotel.hotel.name === activeHotelCard ? "true" : "false"
|
||||
isHotelActiveInMapView(hotel.hotel.name) ? "true" : "false"
|
||||
}
|
||||
>
|
||||
<HotelCard
|
||||
hotelData={hotel}
|
||||
isUserLoggedIn={isUserLoggedIn}
|
||||
state={
|
||||
hotel.hotel.name === activeHotelCard ? "active" : "default"
|
||||
isHotelActiveInMapView(hotel.hotel.name)
|
||||
? "active"
|
||||
: "default"
|
||||
}
|
||||
type={type}
|
||||
bookingCode={bookingCode}
|
||||
|
||||
Reference in New Issue
Block a user