From 56720ed187cb3622984400bf322661540da9aa6a Mon Sep 17 00:00:00 2001 From: Daniel Heppner Date: Tue, 24 Oct 2023 15:35:18 -0700 Subject: [PATCH] add hovered stop support --- ...tops-overlay.js => connected-stops-overlay.ts} | 15 +++++++++++---- lib/components/viewers/nearby/stop.tsx | 14 +++++++++++++- package.json | 2 +- yarn.lock | 8 ++++---- 4 files changed, 29 insertions(+), 10 deletions(-) rename lib/components/map/{connected-stops-overlay.js => connected-stops-overlay.ts} (76%) diff --git a/lib/components/map/connected-stops-overlay.js b/lib/components/map/connected-stops-overlay.ts similarity index 76% rename from lib/components/map/connected-stops-overlay.js rename to lib/components/map/connected-stops-overlay.ts index 4b341ee6a..65b559479 100644 --- a/lib/components/map/connected-stops-overlay.js +++ b/lib/components/map/connected-stops-overlay.ts @@ -1,17 +1,21 @@ import { connect } from 'react-redux' +import { Stop } from '@opentripplanner/types' import StopsOverlay from '@opentripplanner/stops-overlay' import * as apiActions from '../../actions/api' import * as mapActions from '../../actions/map' import * as uiActions from '../../actions/ui' import { MainPanelContent } from '../../actions/ui-constants' +import { Pattern } from '../util/types' // connect to the redux store -const mapStateToProps = (state) => { - const { mainPanelContent, viewedRoute } = state.otp.ui +const mapStateToProps = (state: any) => { + const { highlightedStop, mainPanelContent, viewedRoute } = state.otp.ui const { patternId, routeId } = viewedRoute || {} - const { patterns, v2 } = state.otp.transitIndex.routes?.[routeId] || {} + // FIXME: What type to use here? We don't have one that matches for Pattern. + const { patterns, v2 }: { patterns: Record; v2: boolean } = + state.otp.transitIndex.routes?.[routeId] || {} const visible = mainPanelContent !== MainPanelContent.STOP_VIEWER let minZoom = 15 @@ -23,7 +27,7 @@ const mapStateToProps = (state) => { patterns ) { // Avoid duplicates. - const stopsById = {} + const stopsById: Record = {} // Display stops for the selected pattern for a route. if (v2 && !patternId) { // If a flex route is being shown, show flex zones from all patterns @@ -44,12 +48,15 @@ const mapStateToProps = (state) => { // Override the minimum zoom so that the stops appear even if zoomed out minZoom = 2 + } else if (mainPanelContent === MainPanelContent.NEARBY_VIEW) { + stops = state.otp.overlay.transit.stops } else if (visible) { // Display all stops if no route is shown. stops = state.otp.overlay.transit.stops } return { + highlightedStop, minZoom, stops, visible diff --git a/lib/components/viewers/nearby/stop.tsx b/lib/components/viewers/nearby/stop.tsx index c2d67b4e0..3e106cf46 100644 --- a/lib/components/viewers/nearby/stop.tsx +++ b/lib/components/viewers/nearby/stop.tsx @@ -65,6 +65,7 @@ const getTimezoneWarning = (homeTimezone: string): JSX.Element => { type Props = { homeTimezone: string + setHoveredStop: (stopId: string | undefined) => void setLocation: (args: any) => void setViewedStop: (stop: any, nearby: string) => void showOperatorLogo: boolean @@ -74,6 +75,7 @@ type Props = { const Stop = ({ homeTimezone, + setHoveredStop, setLocation, setViewedStop, stopData, @@ -133,8 +135,17 @@ const Stop = ({ zoomToPlace(map.default, stopData) } + const onMouseEnter = () => { + zoomToStop() + setHoveredStop(stopData.gtfsId) + } + + const onMouseLeave = () => { + setHoveredStop(undefined) + } + return ( - + {stopData.name}
@@ -178,6 +189,7 @@ const Stop = ({ } const mapDispatchToProps = { + setHoveredStop: uiActions.setHoveredStop, setLocation: mapActions.setLocation, setMainPanelContent: uiActions.setMainPanelContent, setViewedStop: uiActions.setViewedStop, diff --git a/package.json b/package.json index 1ed0de4e2..3b6c23e5b 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "@opentripplanner/park-and-ride-overlay": "^2.0.6", "@opentripplanner/route-viewer-overlay": "^2.0.14", "@opentripplanner/stop-viewer-overlay": "^2.0.7", - "@opentripplanner/stops-overlay": "5.1.3-alpha.2", + "@opentripplanner/stops-overlay": "5.2.0-alpha.1", "@opentripplanner/transit-vehicle-overlay": "^4.0.6", "@opentripplanner/transitive-overlay": "^3.0.16", "@opentripplanner/trip-details": "^5.0.4", diff --git a/yarn.lock b/yarn.lock index a7518c1cc..fe1b2cd86 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2579,10 +2579,10 @@ "@opentripplanner/base-map" "^3.0.14" "@opentripplanner/core-utils" "^11.0.2" -"@opentripplanner/stops-overlay@5.1.3-alpha.2": - version "5.1.3-alpha.2" - resolved "https://registry.yarnpkg.com/@opentripplanner/stops-overlay/-/stops-overlay-5.1.3-alpha.2.tgz#851d4b62e12ea2d7340736cead68b6c59dbe699c" - integrity sha512-m2cgefneXUNjsc9O1mQf3dZrgiOJMQ+JXJ1dzg4NFwM0Qpv2bTb2MgC3YKF9/iRgBA+3VEZd/vucm6etLr2BOw== +"@opentripplanner/stops-overlay@5.2.0-alpha.1": + version "5.2.0-alpha.1" + resolved "https://registry.yarnpkg.com/@opentripplanner/stops-overlay/-/stops-overlay-5.2.0-alpha.1.tgz#30deb1655f7f80f24f1853aeaa7f5822b530ba05" + integrity sha512-ku1DZsJukgFA9ipXtXFCvGw5xe5YHOwcJHFIFpQA5gZZftO3Dp8Err7cjUkB/xSpmmwX+l4n5Xct6kscaot5qA== dependencies: "@opentripplanner/base-map" "^3.0.14" "@opentripplanner/from-to-location-picker" "^2.1.8"