Files
TREK/client/src/components/Map/selectedPlaceTarget.ts
T
Maurice 362b1ee8d1 fix(map): a selected stay is flown to even when no pin stands for it
With the Unplanned filter on, a click on a stop in the day list moved the
map while a click on the stay chip did nothing: the map only went to a
selected place it showed as a pin, and the GL map also to one of the open
day's stops, which a stay is neither. Both renderers now look the target
up the same way, the pin first, then the day's stop, then the selected
place itself, so the map goes to the stay whatever filter hides its pin.
2026-09-23 22:11:51 +02:00

28 lines
1003 B
TypeScript

/** A place the map can go to. */
export interface MapTarget {
id: number
lat?: number | null
lng?: number | null
}
/**
* Where the map goes when a place is selected, the same in both renderers.
*
* Its pin first, then the open day's stop, then the selected place itself. A filter
* that hides the pin (Unplanned, a category) keeps the pin off the map but not the
* map away from the place, and a stay shown as a chip in the day list is neither a
* pin under Unplanned nor one of the day's stops, so a click on it used to leave the
* map where it was while a click on a stop moved it (#2488).
*/
export function selectedPlaceTarget<P extends MapTarget>(
selectedPlaceId: number | null | undefined,
places: P[],
dayPlaces: P[],
selectedPlace?: P | null,
): P | null {
if (!selectedPlaceId) return null
return places.find(p => p.id === selectedPlaceId)
?? dayPlaces.find(p => p.id === selectedPlaceId)
?? (selectedPlace?.id === selectedPlaceId ? selectedPlace : null)
}