Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nearby-view): Avoid blank nearby view on mobile #1264

Merged
merged 4 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading