diff --git a/__tests__/components/viewers/__snapshots__/nearby-view.js.snap b/__tests__/components/viewers/__snapshots__/nearby-view.js.snap index b20164dd6..48064f0f4 100644 --- a/__tests__/components/viewers/__snapshots__/nearby-view.js.snap +++ b/__tests__/components/viewers/__snapshots__/nearby-view.js.snap @@ -31,6 +31,7 @@ exports[`components > viewers > nearby view renders nothing on a blank page 1`] "fetching": false, } } + defaultLatLon={null} fetchNearby={[Function]} homeTimezone="America/Los_Angeles" nearby={Array []} @@ -146,6 +147,7 @@ exports[`components > viewers > nearby view renders proper scooter dates 1`] = ` "fetching": false, } } + defaultLatLon={null} fetchNearby={[Function]} homeTimezone="America/Los_Angeles" nearby={ diff --git a/lib/components/viewers/nearby/nearby-view.tsx b/lib/components/viewers/nearby/nearby-view.tsx index 9f4b24310..653f3716a 100644 --- a/lib/components/viewers/nearby/nearby-view.tsx +++ b/lib/components/viewers/nearby/nearby-view.tsx @@ -34,6 +34,7 @@ type CurrentPosition = { coords?: { latitude: number; longitude: number } } type Props = { currentPosition?: CurrentPosition + defaultLatLon: LatLonObj | null displayedCoords?: LatLonObj entityId?: string fetchNearby: (latLon: LatLonObj, radius?: number) => void @@ -73,7 +74,8 @@ const getNearbyItem = (place: any) => { function getNearbyCoordsFromUrlOrLocationOrMapCenter( coordsFromUrl?: LatLonObj, currentPosition?: CurrentPosition, - map?: MapRef + map?: MapRef, + defaultLatLon?: LatLonObj | null ): LatLonObj | null { if (coordsFromUrl) { return coordsFromUrl @@ -92,11 +94,15 @@ function getNearbyCoordsFromUrlOrLocationOrMapCenter( if (mapCoords) { return mapCoords } + if (defaultLatLon) { + return defaultLatLon + } return null } function NearbyView({ currentPosition, + defaultLatLon, displayedCoords, entityId, fetchNearby, @@ -119,7 +125,8 @@ function NearbyView({ getNearbyCoordsFromUrlOrLocationOrMapCenter( nearbyViewCoords, currentPosition, - map + map, + defaultLatLon ), [nearbyViewCoords, currentPosition, map] ) @@ -283,12 +290,16 @@ function NearbyView({ const mapStateToProps = (state: AppReduxState) => { const { config, location, transitIndex, ui } = state.otp + const { map } = state.otp.config const { nearbyViewCoords } = ui const { nearby } = transitIndex const { entityId } = state.router.location.query const { currentPosition } = location + const defaultLatLon = + map?.initLat && map?.initLon ? { lat: map.initLat, lon: map.initLon } : null return { currentPosition, + defaultLatLon, displayedCoords: nearby?.coords, entityId: entityId && decodeURIComponent(entityId), homeTimezone: config.homeTimezone,