Skip to content

Commit

Permalink
add hovered stop support
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-heppner-ibigroup committed Oct 24, 2023
1 parent 9dc251c commit 56720ed
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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<string, any>; v2: boolean } =
state.otp.transitIndex.routes?.[routeId] || {}
const visible = mainPanelContent !== MainPanelContent.STOP_VIEWER

let minZoom = 15
Expand All @@ -23,7 +27,7 @@ const mapStateToProps = (state) => {
patterns
) {
// Avoid duplicates.
const stopsById = {}
const stopsById: Record<string, Stop> = {}
// 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
Expand All @@ -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
Expand Down
14 changes: 13 additions & 1 deletion lib/components/viewers/nearby/stop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -74,6 +75,7 @@ type Props = {

const Stop = ({
homeTimezone,
setHoveredStop,
setLocation,
setViewedStop,
stopData,
Expand Down Expand Up @@ -133,8 +135,17 @@ const Stop = ({
zoomToPlace(map.default, stopData)
}

const onMouseEnter = () => {
zoomToStop()
setHoveredStop(stopData.gtfsId)
}

const onMouseLeave = () => {
setHoveredStop(undefined)
}

return (
<Card onMouseEnter={zoomToStop}>
<Card onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
<CardHeader>{stopData.name}</CardHeader>
<CardBody>
<div>
Expand Down Expand Up @@ -178,6 +189,7 @@ const Stop = ({
}

const mapDispatchToProps = {
setHoveredStop: uiActions.setHoveredStop,
setLocation: mapActions.setLocation,
setMainPanelContent: uiActions.setMainPanelContent,
setViewedStop: uiActions.setViewedStop,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 56720ed

Please sign in to comment.