diff --git a/app/component/StopNearYou.js b/app/component/StopNearYou.js index 3de0d74e06..070d9bf413 100644 --- a/app/component/StopNearYou.js +++ b/app/component/StopNearYou.js @@ -16,9 +16,11 @@ const StopNearYou = ( { stop, desc, stopId, currentTime, currentMode, relay }, { config, intl }, ) => { + if (!stop.stoptimesWithoutPatterns) { + return null; + } const [capacityModalOpen, setCapacityModalOpen] = useState(false); - const stopOrStation = stop.parentStation ? stop.parentStation : stop; - const stopMode = stopOrStation.stoptimesWithoutPatterns[0]?.trip.route.mode; + const stopMode = stop.stoptimesWithoutPatterns[0]?.trip.route.mode; useEffect(() => { let id = stop.gtfsId; if (stopId) { @@ -31,9 +33,8 @@ const StopNearYou = ( } }, [currentTime, currentMode]); const description = desc || stop.desc; - const isStation = !!stop.parentStation || !!stopId; - const gtfsId = - (stop.parentStation && stop.parentStation.gtfsId) || stop.gtfsId; + const isStation = stop.locationType === 'STATION'; + const { gtfsId } = stop; const urlEncodedGtfsId = gtfsId.replace('/', '%2F'); const linkAddress = isStation ? `/${PREFIX_TERMINALS}/${urlEncodedGtfsId}` @@ -49,7 +50,7 @@ const StopNearYou = (
setCapacityModalOpen(true)} /> diff --git a/app/component/StopNearYouContainer.js b/app/component/StopNearYouContainer.js index f42b72e468..70a34cbf64 100644 --- a/app/component/StopNearYouContainer.js +++ b/app/component/StopNearYouContainer.js @@ -27,6 +27,7 @@ const containerComponent = createRefetchContainer( } zoneId platformCode + locationType stoptimesWithoutPatterns( startTime: $startTime omitNonPickups: $omitNonPickups @@ -67,58 +68,6 @@ const containerComponent = createRefetchContainer( } } } - parentStation { - id - name - gtfsId - code - desc - lat - lon - zoneId - platformCode - alerts { - alertSeverityLevel - alertDescriptionText - } - stoptimesWithoutPatterns( - startTime: $startTime - omitNonPickups: $omitNonPickups - ) { - stop { - platformCode - } - realtimeDeparture - realtime - serviceDay - headsign - trip { - gtfsId - occupancy { - occupancyStatus - } - pattern { - code - route { - gtfsId - } - } - route { - alerts { - alertSeverityLevel - } - type - shortName - longName - gtfsId - mode - patterns { - headsign - } - } - } - } - } } `, }, @@ -132,6 +81,11 @@ const containerComponent = createRefetchContainer( ...StopNearYouContainer_stop @arguments(startTime: $startTime, omitNonPickups: $omitNonPickups) } + + station(id: $stopId) { + ...StopNearYouContainer_stop + @arguments(startTime: $startTime, omitNonPickups: $omitNonPickups) + } } `, ); diff --git a/app/component/StopsNearYouContainer.js b/app/component/StopsNearYouContainer.js index d8f8001e5e..3aaf74704d 100644 --- a/app/component/StopsNearYouContainer.js +++ b/app/component/StopsNearYouContainer.js @@ -58,7 +58,6 @@ class StopsNearYouContainer extends React.Component { static getDerivedStateFromProps = (nextProps, prevState) => { let newState = null; - const terminals = []; if ( !prevState.currentPosition || (!prevState.currentPosition.address && @@ -70,36 +69,18 @@ class StopsNearYouContainer extends React.Component { currentPosition: nextProps.position, }; } - const checkStops = (t, n) => { - return n.every(stop => { - return ( - stop.node.place.parentStation && - t.indexOf(stop.node.place.parentStation.name) !== -1 - ); - }); - }; if (nextProps.stopPatterns) { const stopsForFiltering = [...nextProps.stopPatterns.nearest.edges]; const newestStops = stopsForFiltering.splice( stopsForFiltering.length - 5, ); - stopsForFiltering.forEach(stop => { - const node = stop.node.place; - if ( - node.parentStation && - terminals.indexOf(node.parentStation.name) === -1 - ) { - terminals.push(node.parentStation.name); - } - }); if ( - (newestStops.every(stop => { + newestStops.every(stop => { return ( stop.node.place.stoptimesWithoutPatterns && stop.node.place.stoptimesWithoutPatterns.length === 0 ); - }) || - checkStops(terminals, newestStops)) && + }) && prevState.refetches < prevState.maxRefetches ) { newState = { @@ -199,7 +180,6 @@ class StopsNearYouContainer extends React.Component { const walkRoutingThreshold = mode === 'RAIL' || mode === 'SUBWAY' || mode === 'FERRY' ? 3000 : 1500; const stopPatterns = this.props.stopPatterns.nearest.edges; - const terminalNames = []; const isCityBikeView = this.props.match.params.mode === 'CITYBIKE'; let sortedPatterns; if (isCityBikeView) { @@ -232,27 +212,13 @@ class StopsNearYouContainer extends React.Component { stop.stoptimesWithoutPatterns.length > 0 ) { if (!this.props.prioritizedStops?.includes(stop.gtfsId)) { - if (stop.parentStation) { - if (terminalNames.indexOf(stop.parentStation.name) === -1) { - terminalNames.push(stop.parentStation.name); - return ( - - ); - } - } else { - return ( - - ); - } + return ( + + ); } } break; @@ -414,9 +380,6 @@ const refetchContainer = createPaginationContainer( ) { scheduledArrival } - parentStation { - name - } } } } diff --git a/app/component/StopsNearYouFavoritesMapContainer.js b/app/component/StopsNearYouFavoritesMapContainer.js index fd8b593cea..076ba1ba32 100644 --- a/app/component/StopsNearYouFavoritesMapContainer.js +++ b/app/component/StopsNearYouFavoritesMapContainer.js @@ -92,12 +92,6 @@ const containerComponent = createFragmentContainer(StopsNearYouMapWithStores, { lat lon name - parentStation { - lat - lon - name - gtfsId - } patterns { route { gtfsId diff --git a/app/component/StopsNearYouFavouritesContainer.js b/app/component/StopsNearYouFavouritesContainer.js index a2bba60bfb..d95351692d 100644 --- a/app/component/StopsNearYouFavouritesContainer.js +++ b/app/component/StopsNearYouFavouritesContainer.js @@ -50,20 +50,12 @@ function StopsNearYouFavouritesContainer({ const stopElements = stopList.map(stop => { switch (stop.type) { case 'stop': - return ( - - ); case 'station': return ( ); case 'vehicleRentalStation': diff --git a/app/component/StopsNearYouMapContainer.js b/app/component/StopsNearYouMapContainer.js index 170fc05ecb..361cf34e7d 100644 --- a/app/component/StopsNearYouMapContainer.js +++ b/app/component/StopsNearYouMapContainer.js @@ -76,12 +76,6 @@ const containerComponent = createPaginationContainer( lat lon name - parentStation { - lat - lon - name - gtfsId - } patterns { route { gtfsId @@ -95,6 +89,21 @@ const containerComponent = createPaginationContainer( points } } + stops { + patterns { + route { + gtfsId + shortName + mode + type + } + code + directionId + patternGeometry { + points + } + } + } stoptimesWithoutPatterns( startTime: $startTime omitNonPickups: $omitNonPickups @@ -115,11 +124,20 @@ const containerComponent = createPaginationContainer( lat lon name - parentStation { - lat - lon - name - gtfsId + stops { + patterns { + route { + gtfsId + shortName + mode + type + } + code + directionId + patternGeometry { + points + } + } } patterns { route { diff --git a/app/component/StopsNearYouPage.js b/app/component/StopsNearYouPage.js index 2901a15f32..66b9632d01 100644 --- a/app/component/StopsNearYouPage.js +++ b/app/component/StopsNearYouPage.js @@ -213,7 +213,7 @@ class StopsNearYouPage extends React.Component { getQueryVariables = mode => { const { searchPosition } = this.state; - let placeTypes = 'STOP'; + let placeTypes = ['STOP', 'STATION']; let modes = [mode]; if (mode === 'CITYBIKE') { placeTypes = 'BICYCLE_RENT'; diff --git a/app/component/map/StopsNearYouMap.js b/app/component/map/StopsNearYouMap.js index 18973ad2f4..729fbadd71 100644 --- a/app/component/map/StopsNearYouMap.js +++ b/app/component/map/StopsNearYouMap.js @@ -5,7 +5,6 @@ import { graphql, fetchQuery } from 'react-relay'; import moment from 'moment'; import uniqBy from 'lodash/uniqBy'; import compact from 'lodash/compact'; -import indexOf from 'lodash/indexOf'; import isEqual from 'lodash/isEqual'; import polyline from 'polyline-encoded'; import distance from '@digitransit-search-util/digitransit-search-util-distance'; @@ -37,20 +36,9 @@ const locationMarkerModules = { importLazy(import(/* webpackChunkName: "map" */ './LocationMarker')), }; const handleStopsAndStations = edges => { - const terminalNames = []; const stopsAndStations = edges.map(({ node }) => { const stop = { ...node.place, distance: node.distance }; - if ( - stop.parentStation && - indexOf(terminalNames, stop.parentStation.name) === -1 - ) { - terminalNames.push(stop.parentStation.name); - return { ...stop.parentStation, distance: node.distance }; - } - if (!stop.parentStation) { - return stop; - } - return null; + return stop; }); return compact(stopsAndStations); }; diff --git a/app/util/sortUtils.js b/app/util/sortUtils.js index f7f559891e..4f439f48bc 100644 --- a/app/util/sortUtils.js +++ b/app/util/sortUtils.js @@ -24,21 +24,16 @@ export const sortNearbyRentalStations = favouriteRentalStationsIds => { }; /** - * Sorts favourite stops or stations first. Prioritizes stations if they are within - * a given distance + * Sorts favourite stops or stations first. * * @param {Set} favouriteStopIds gtfsIds of favourite stops and stations. * @param distanceThreshold maximum distance with which the stops are priorized */ export const sortNearbyStops = (favouriteStopIds, distanceThreshold) => { return (first, second) => { - const firstStopOrStationId = first.node.place.parentStation - ? first.node.place.parentStation.gtfsId - : first.node.place.gtfsId; + const firstStopOrStationId = first.node.place.gtfsId; const firstStopOrStationIsClose = first.node.distance < distanceThreshold; - const secondStopOrStationId = second.node.place.parentStation - ? second.node.place.parentStation.gtfsId - : second.node.place.gtfsId; + const secondStopOrStationId = second.node.place.gtfsId; const secondStopOrStationIsClose = second.node.distance < distanceThreshold; const firstIsFavourite = favouriteStopIds.has(firstStopOrStationId) && firstStopOrStationIsClose;