Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlay Popup Behavior Correction #1288

Merged
merged 6 commits into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 15 additions & 24 deletions lib/components/map/itinerary-summary-overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Marker } from 'react-map-gl'
import centroid from '@turf/centroid'
import distance from '@turf/distance'
import polyline from '@mapbox/polyline'
import React, { useContext, useState } from 'react'
import React, { useContext } from 'react'
import styled from 'styled-components'

import * as narriativeActions from '../../actions/narrative'
Expand Down Expand Up @@ -147,19 +147,20 @@ const ItinerarySummaryOverlay = ({
// @ts-expect-error React context is populated dynamically
const { LegIcon } = useContext(ComponentContext)

const [sharedTimeout, setSharedTimeout] = useState<null | NodeJS.Timeout>(
null
)

if (!itins || !visible) return <></>
const mergedItins: ItinWithGeometry[] = addTrueIndex(
doMergeItineraries(itins).mergedItineraries.map(addItinLineString)
const indexedItins: ItinWithGeometry[] = addTrueIndex(
itins.map(addItinLineString)
)
const mergedItins: ItinWithGeometry[] =
doMergeItineraries(indexedItins).mergedItineraries

const midPoints = mergedItins.reduce<ItinUniquePoint[]>(
(prev: ItinUniquePoint[], curItin: ItinWithGeometry) => {
prev.push(getUniquePoint(curItin, prev))
return prev
},
[]
)

const midPoints = mergedItins.reduce<ItinUniquePoint[]>((prev, curItin) => {
prev.push(getUniquePoint(curItin, prev))
return prev
}, [])
// The first point is probably not well placed, so let's run the algorithm again
if (midPoints.length > 1) {
midPoints[0] = getUniquePoint(mergedItins[0], midPoints)
Expand All @@ -186,18 +187,8 @@ const ItinerarySummaryOverlay = ({
onClick={() => {
setActive({ index: mp.itin.index })
}}
// TODO: useCallback here (getting weird errors?)
onMouseEnter={() => {
setSharedTimeout(
setTimeout(() => {
setVisible({ index: mp.itin.index })
}, 150)
)
}}
onMouseLeave={() => {
sharedTimeout && clearTimeout(sharedTimeout)
setVisible({ index: null })
}}
// TODO: restore setting visible itinerary on hover without
// causing endless re-render?
>
<MetroItineraryRoutes
expanded={false}
Expand Down
Loading