Skip to content

Commit

Permalink
Merge branch 'dev' into nearby-view-cleanup-aug-2024
Browse files Browse the repository at this point in the history
  • Loading branch information
amy-corson-ibigroup authored Sep 10, 2024
2 parents f2414c2 + 65abb40 commit bae6e99
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 []}
Expand Down Expand Up @@ -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={
Expand Down
15 changes: 13 additions & 2 deletions lib/components/viewers/nearby/nearby-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -92,11 +94,15 @@ function getNearbyCoordsFromUrlOrLocationOrMapCenter(
if (mapCoords) {
return mapCoords
}
if (defaultLatLon) {
return defaultLatLon
}
return null
}

function NearbyView({
currentPosition,
defaultLatLon,
displayedCoords,
entityId,
fetchNearby,
Expand All @@ -119,7 +125,8 @@ function NearbyView({
getNearbyCoordsFromUrlOrLocationOrMapCenter(
nearbyViewCoords,
currentPosition,
map
map,
defaultLatLon
),
[nearbyViewCoords, currentPosition, map]
)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit bae6e99

Please sign in to comment.