Skip to content

Commit

Permalink
fix(nearby-view): don't flash stale data while loading new response
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-heppner-ibigroup committed Apr 4, 2024
1 parent 03248ff commit 57a23ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lib/actions/apiV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,11 @@ export const fetchNearby = (position, radius) => {
error.cause = payload.errors
throw error
}
return mergeSameStops(payload.data?.nearest?.edges)
return {
data: mergeSameStops(payload.data?.nearest?.edges),
lat,
lon
}
}
}
)
Expand Down
9 changes: 5 additions & 4 deletions lib/components/viewers/nearby/nearby-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ function NearbyView({
nearbyViewCoords,
radius,
setHighlightedLocation,
setLocation,
setMainPanelContent,
setViewedNearbyCoords,
zoomToPlace
Expand All @@ -93,7 +92,7 @@ function NearbyView({
}, [location, setHighlightedLocation])

useEffect(() => {
const moveListener = (e: any) => {
const moveListener = (e: mapboxgl.EventData) => {
if (e.geolocateSource) {
setViewedNearbyCoords({
lat: e.viewState.latitude,
Expand All @@ -102,7 +101,7 @@ function NearbyView({
}
}

const dragListener = (e: any) => {
const dragListener = (e: mapboxgl.EventData) => {
const coords = {
lat: e.viewState.latitude,
lon: e.viewState.longitude
Expand Down Expand Up @@ -255,11 +254,13 @@ const mapStateToProps = (state: AppReduxState) => {
const { nearbyViewCoords } = ui
const { nearby } = transitIndex
const { entityId } = state.router.location.query
const showNearby =
nearby?.lat === nearbyViewCoords.lat && nearby?.lon === nearbyViewCoords.lon
return {
entityId: entityId && decodeURIComponent(entityId),
homeTimezone: config.homeTimezone,
location: state.router.location.hash,
nearby,
nearby: showNearby ? nearby?.data : null,
nearbyViewCoords,
radius: config.nearbyView?.radius
}
Expand Down

0 comments on commit 57a23ec

Please sign in to comment.