mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-22 06:56:35 +00:00
362b1ee8d1
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.
28 lines
1003 B
TypeScript
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)
|
|
}
|