fix(SW-3203): Added property id to pointOfInterestSchema to handle identical names
Approved-by: Matilda Landström Approved-by: Chuma Mcphoy (We Ahead)
This commit is contained in:
@@ -13,9 +13,18 @@ import { translatePOIGroup } from "./util"
|
|||||||
|
|
||||||
import styles from "./sidebar.module.css"
|
import styles from "./sidebar.module.css"
|
||||||
|
|
||||||
import type { SidebarProps } from "@/types/components/hotelPage/map/sidebar"
|
import type { PointOfInterest } from "@scandic-hotels/trpc/types/hotel"
|
||||||
|
|
||||||
import type { Coordinates } from "@/types/components/maps/coordinates"
|
import type { Coordinates } from "@/types/components/maps/coordinates"
|
||||||
|
|
||||||
|
interface SidebarProps {
|
||||||
|
hotelName: string
|
||||||
|
pointsOfInterest: PointOfInterest[]
|
||||||
|
activePoi: PointOfInterest["name"] | null
|
||||||
|
onActivePoiChange: (poi: PointOfInterest["name"] | null) => void
|
||||||
|
coordinates: Coordinates
|
||||||
|
}
|
||||||
|
|
||||||
export default function Sidebar({
|
export default function Sidebar({
|
||||||
activePoi,
|
activePoi,
|
||||||
hotelName,
|
hotelName,
|
||||||
@@ -62,23 +71,23 @@ export default function Sidebar({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMouseEnter(poiName: string | undefined) {
|
function handleMouseEnter(poiId: string | undefined) {
|
||||||
if (!poiName) return
|
if (!poiId) return
|
||||||
|
|
||||||
if (!isClicking) {
|
if (!isClicking) {
|
||||||
onActivePoiChange(poiName)
|
onActivePoiChange(poiId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handlePoiClick(
|
function handlePoiClick(
|
||||||
poiName: string | undefined,
|
poiId: string | undefined,
|
||||||
poiCoordinates: Coordinates
|
poiCoordinates: Coordinates
|
||||||
) {
|
) {
|
||||||
if (!poiName || !poiCoordinates) return
|
if (!poiId || !poiCoordinates) return
|
||||||
|
|
||||||
setIsClicking(true)
|
setIsClicking(true)
|
||||||
toggleFullScreenSidebar()
|
toggleFullScreenSidebar()
|
||||||
onActivePoiChange(poiName)
|
onActivePoiChange(poiId)
|
||||||
moveToPoi(poiCoordinates)
|
moveToPoi(poiCoordinates)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setIsClicking(false)
|
setIsClicking(false)
|
||||||
@@ -130,18 +139,13 @@ export default function Sidebar({
|
|||||||
</Typography>
|
</Typography>
|
||||||
<ul className={styles.poiList}>
|
<ul className={styles.poiList}>
|
||||||
{pois.map((poi) => (
|
{pois.map((poi) => (
|
||||||
<li
|
<li key={poi.id} className={styles.poiItem}>
|
||||||
key={poi.name + poi.categoryName}
|
|
||||||
className={styles.poiItem}
|
|
||||||
>
|
|
||||||
<ButtonRAC
|
<ButtonRAC
|
||||||
className={cx(styles.poiButton, {
|
className={cx(styles.poiButton, {
|
||||||
[styles.active]: activePoi === poi.name,
|
[styles.active]: activePoi === poi.id,
|
||||||
})}
|
})}
|
||||||
onHoverStart={() => handleMouseEnter(poi.name)}
|
onHoverStart={() => handleMouseEnter(poi.id)}
|
||||||
onPress={() =>
|
onPress={() => handlePoiClick(poi.id, poi.coordinates)}
|
||||||
handlePoiClick(poi.name, poi.coordinates)
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<Typography variant="Body/Paragraph/mdRegular">
|
<Typography variant="Body/Paragraph/mdRegular">
|
||||||
<span>{poi.name}</span>
|
<span>{poi.name}</span>
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
import type { PointOfInterest } from "@scandic-hotels/trpc/types/hotel"
|
|
||||||
import type { Coordinates } from "../../maps/coordinates"
|
|
||||||
|
|
||||||
export interface SidebarProps {
|
|
||||||
hotelName: string
|
|
||||||
pointsOfInterest: PointOfInterest[]
|
|
||||||
activePoi: PointOfInterest["name"] | null
|
|
||||||
onActivePoiChange: (poi: PointOfInterest["name"] | null) => void
|
|
||||||
coordinates: Coordinates
|
|
||||||
}
|
|
||||||
@@ -31,8 +31,8 @@ export default function PoiMapMarkers({
|
|||||||
}: PoiMapMarkersProps) {
|
}: PoiMapMarkersProps) {
|
||||||
const intl = useIntl()
|
const intl = useIntl()
|
||||||
|
|
||||||
function toggleActivePoi(poiName: string) {
|
function toggleActivePoi(poiId: string) {
|
||||||
onActivePoiChange?.(activePoi === poiName ? null : poiName)
|
onActivePoiChange?.(activePoi === poiId ? null : poiId)
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -45,22 +45,22 @@ export default function PoiMapMarkers({
|
|||||||
|
|
||||||
{pointsOfInterest.map((poi) => (
|
{pointsOfInterest.map((poi) => (
|
||||||
<AdvancedMarker
|
<AdvancedMarker
|
||||||
key={poi.name + poi.categoryName}
|
key={poi.id}
|
||||||
className={styles.advancedMarker}
|
className={styles.advancedMarker}
|
||||||
position={poi.coordinates}
|
position={poi.coordinates}
|
||||||
anchorPoint={AdvancedMarkerAnchorPoint.CENTER}
|
anchorPoint={AdvancedMarkerAnchorPoint.CENTER}
|
||||||
zIndex={activePoi === poi.name ? 2 : 0}
|
zIndex={activePoi === poi.id ? 2 : 0}
|
||||||
onMouseEnter={() => onActivePoiChange?.(poi.name ?? null)}
|
onMouseEnter={() => onActivePoiChange?.(poi.id ?? null)}
|
||||||
onMouseLeave={() => onActivePoiChange?.(null)}
|
onMouseLeave={() => onActivePoiChange?.(null)}
|
||||||
onClick={() => toggleActivePoi(poi.name ?? '')}
|
onClick={() => toggleActivePoi(poi.id ?? '')}
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
className={`${styles.poi} ${activePoi === poi.name ? styles.active : ''}`}
|
className={`${styles.poi} ${activePoi === poi.id ? styles.active : ''}`}
|
||||||
>
|
>
|
||||||
<PoiMarker
|
<PoiMarker
|
||||||
group={poi.group}
|
group={poi.group}
|
||||||
categoryName={poi.categoryName}
|
categoryName={poi.categoryName}
|
||||||
size={activePoi === poi.name ? 'large' : 'small'}
|
size={activePoi === poi.id ? 'large' : 'small'}
|
||||||
/>
|
/>
|
||||||
<span className={styles.poiLabel}>
|
<span className={styles.poiLabel}>
|
||||||
<Typography variant="Body/Paragraph/mdRegular">
|
<Typography variant="Body/Paragraph/mdRegular">
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export const pointOfInterestSchema = z
|
|||||||
name: nullableStringValidator,
|
name: nullableStringValidator,
|
||||||
})
|
})
|
||||||
.transform((poi) => ({
|
.transform((poi) => ({
|
||||||
|
id: `${poi.name}-${poi.location.latitude}-${poi.location.longitude}`,
|
||||||
categoryName: poi.category.name,
|
categoryName: poi.category.name,
|
||||||
coordinates: {
|
coordinates: {
|
||||||
lat: poi.location.latitude,
|
lat: poi.location.latitude,
|
||||||
|
|||||||
Reference in New Issue
Block a user