fix(SW-984): Scroll to active card (desktop)

This commit is contained in:
Pontus Dreij
2024-11-25 13:27:19 +01:00
parent 333be1379c
commit 0283c777ca
3 changed files with 25 additions and 8 deletions

View File

@@ -3,4 +3,6 @@
flex-direction: column; flex-direction: column;
gap: var(--Spacing-x2); gap: var(--Spacing-x2);
margin-bottom: var(--Spacing-x2); margin-bottom: var(--Spacing-x2);
max-height: 100vh;
overflow-y: auto;
} }

View File

@@ -109,13 +109,17 @@ export default function HotelCardListing({
<section className={styles.hotelCards}> <section className={styles.hotelCards}>
{hotels?.length ? ( {hotels?.length ? (
hotels.map((hotel) => ( hotels.map((hotel) => (
<HotelCard <div
key={hotel.hotelData.operaId} key={hotel.hotelData.operaId}
hotel={hotel} data-active={hotel.hotelData.name === activeCard ? "true" : "false"}
type={type} >
state={hotel.hotelData.name === activeCard ? "active" : "default"} <HotelCard
onHotelCardHover={onHotelCardHover} hotel={hotel}
/> type={type}
state={hotel.hotelData.name === activeCard ? "active" : "default"}
onHotelCardHover={onHotelCardHover}
/>
</div>
)) ))
) : activeFilters ? ( ) : activeFilters ? (
<Alert <Alert

View File

@@ -1,7 +1,7 @@
"use client" "use client"
import { APIProvider } from "@vis.gl/react-google-maps" import { APIProvider } from "@vis.gl/react-google-maps"
import { useRouter, useSearchParams } from "next/navigation" import { useRouter, useSearchParams } from "next/navigation"
import { useEffect, useState } from "react" import { useEffect, useRef, useState } from "react"
import { useIntl } from "react-intl" import { useIntl } from "react-intl"
import { useMediaQuery } from "usehooks-ts" import { useMediaQuery } from "usehooks-ts"
@@ -35,6 +35,7 @@ export default function SelectHotelMap({
const isAboveMobile = useMediaQuery("(min-width: 768px)") const isAboveMobile = useMediaQuery("(min-width: 768px)")
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 selectHotelParams = new URLSearchParams(searchParams.toString()) const selectHotelParams = new URLSearchParams(searchParams.toString())
const selectedHotel = selectHotelParams.get("selectedHotel") const selectedHotel = selectHotelParams.get("selectedHotel")
@@ -43,6 +44,16 @@ export default function SelectHotelMap({
? cityCoordinates ? cityCoordinates
: { ...cityCoordinates, lat: cityCoordinates.lat - 0.006 } : { ...cityCoordinates, lat: cityCoordinates.lat - 0.006 }
useEffect(() => {
if (listingContainerRef.current) {
const activeElement =
listingContainerRef.current.querySelector(`[data-active="true"]`)
if (activeElement) {
activeElement.scrollIntoView({ behavior: "smooth", block: "nearest" })
}
}
}, [activeHotelPin])
useEffect(() => { useEffect(() => {
if (selectedHotel) { if (selectedHotel) {
setActiveHotelPin(selectedHotel) setActiveHotelPin(selectedHotel)
@@ -90,7 +101,7 @@ export default function SelectHotelMap({
return ( return (
<APIProvider apiKey={apiKey}> <APIProvider apiKey={apiKey}>
<div className={styles.container}> <div className={styles.container}>
<div className={styles.listingContainer}> <div className={styles.listingContainer} ref={listingContainerRef}>
<div className={styles.filterContainer}> <div className={styles.filterContainer}>
<Button <Button
intent="text" intent="text"