From a81a2dc592f2c198d1bbe4eb3171a39cb214cb67 Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Tue, 15 Oct 2024 13:18:09 -0400 Subject: [PATCH 1/5] set correct hover index --- .../map/itinerary-summary-overlay.tsx | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/lib/components/map/itinerary-summary-overlay.tsx b/lib/components/map/itinerary-summary-overlay.tsx index aec2823fc..0cab9ad6f 100644 --- a/lib/components/map/itinerary-summary-overlay.tsx +++ b/lib/components/map/itinerary-summary-overlay.tsx @@ -1,6 +1,6 @@ import { connect } from 'react-redux' import { Feature, lineString, LineString, Position } from '@turf/helpers' -import { Itinerary, Location } from '@opentripplanner/types' +import { Itinerary, Leg, Location } from '@opentripplanner/types' import { Marker } from 'react-map-gl' import centroid from '@turf/centroid' import distance from '@turf/distance' @@ -103,6 +103,8 @@ function addTrueIndex(array: ItinWithGeometry[]): ItinWithGeometry[] { return array } +const getLegRoute = (leg: Leg) => leg.routeId + type ItinUniquePoint = { itin: ItinWithGeometry uniquePoint: Position @@ -152,14 +154,18 @@ const ItinerarySummaryOverlay = ({ ) if (!itins || !visible) return <> - const mergedItins: ItinWithGeometry[] = addTrueIndex( - doMergeItineraries(itins).mergedItineraries.map(addItinLineString) + const indexedItins: ItinWithGeometry[] = addTrueIndex( + itins.map(addItinLineString) ) + const mergedItins = doMergeItineraries(indexedItins).mergedItineraries - const midPoints = mergedItins.reduce((prev, curItin) => { - prev.push(getUniquePoint(curItin, prev)) - return prev - }, []) + const midPoints = mergedItins.reduce( + (prev: ItinUniquePoint[], curItin: ItinWithGeometry) => { + 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) @@ -186,18 +192,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? > Date: Tue, 15 Oct 2024 14:31:48 -0400 Subject: [PATCH 2/5] remove dead code --- lib/components/map/itinerary-summary-overlay.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/components/map/itinerary-summary-overlay.tsx b/lib/components/map/itinerary-summary-overlay.tsx index 0cab9ad6f..8df12478e 100644 --- a/lib/components/map/itinerary-summary-overlay.tsx +++ b/lib/components/map/itinerary-summary-overlay.tsx @@ -103,8 +103,6 @@ function addTrueIndex(array: ItinWithGeometry[]): ItinWithGeometry[] { return array } -const getLegRoute = (leg: Leg) => leg.routeId - type ItinUniquePoint = { itin: ItinWithGeometry uniquePoint: Position From dea32116297135eb9355ce3b7c24d546f43eaaf3 Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Tue, 15 Oct 2024 14:32:15 -0400 Subject: [PATCH 3/5] clean up --- lib/components/map/itinerary-summary-overlay.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/components/map/itinerary-summary-overlay.tsx b/lib/components/map/itinerary-summary-overlay.tsx index 8df12478e..d28307b80 100644 --- a/lib/components/map/itinerary-summary-overlay.tsx +++ b/lib/components/map/itinerary-summary-overlay.tsx @@ -1,6 +1,6 @@ import { connect } from 'react-redux' import { Feature, lineString, LineString, Position } from '@turf/helpers' -import { Itinerary, Leg, Location } from '@opentripplanner/types' +import { Itinerary, Location } from '@opentripplanner/types' import { Marker } from 'react-map-gl' import centroid from '@turf/centroid' import distance from '@turf/distance' From c5da17ba64a19faa0df890836e609baddc069abc Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Fri, 1 Nov 2024 11:07:51 -0400 Subject: [PATCH 4/5] add missing typescript --- lib/components/map/itinerary-summary-overlay.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/components/map/itinerary-summary-overlay.tsx b/lib/components/map/itinerary-summary-overlay.tsx index d28307b80..d66e50d45 100644 --- a/lib/components/map/itinerary-summary-overlay.tsx +++ b/lib/components/map/itinerary-summary-overlay.tsx @@ -173,7 +173,10 @@ const ItinerarySummaryOverlay = ({ return ( <> {midPoints.map( - (mp) => + (mp: { + itin: Itinerary & { index: number } + uniquePoint: [number, number] + }) => // If no itinerary is hovered, show all of them. If one is selected, show only that one // TODO: clean up conditionals, move these to a more appropriate place without breaking indexing (isDefined(visibleItinerary) From 6909653a2f2cc6b4f155bc638209cb68b75c382b Mon Sep 17 00:00:00 2001 From: Daniel Heppner Date: Mon, 4 Nov 2024 12:57:11 -0800 Subject: [PATCH 5/5] clean up miles's bad code --- lib/components/map/itinerary-summary-overlay.tsx | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/components/map/itinerary-summary-overlay.tsx b/lib/components/map/itinerary-summary-overlay.tsx index d66e50d45..5f47f527d 100644 --- a/lib/components/map/itinerary-summary-overlay.tsx +++ b/lib/components/map/itinerary-summary-overlay.tsx @@ -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' @@ -147,17 +147,14 @@ const ItinerarySummaryOverlay = ({ // @ts-expect-error React context is populated dynamically const { LegIcon } = useContext(ComponentContext) - const [sharedTimeout, setSharedTimeout] = useState( - null - ) - if (!itins || !visible) return <> const indexedItins: ItinWithGeometry[] = addTrueIndex( itins.map(addItinLineString) ) - const mergedItins = doMergeItineraries(indexedItins).mergedItineraries + const mergedItins: ItinWithGeometry[] = + doMergeItineraries(indexedItins).mergedItineraries - const midPoints = mergedItins.reduce( + const midPoints = mergedItins.reduce( (prev: ItinUniquePoint[], curItin: ItinWithGeometry) => { prev.push(getUniquePoint(curItin, prev)) return prev @@ -173,10 +170,7 @@ const ItinerarySummaryOverlay = ({ return ( <> {midPoints.map( - (mp: { - itin: Itinerary & { index: number } - uniquePoint: [number, number] - }) => + (mp) => // If no itinerary is hovered, show all of them. If one is selected, show only that one // TODO: clean up conditionals, move these to a more appropriate place without breaking indexing (isDefined(visibleItinerary)