From 57a23ec94632fb903c64dd9563cb726f3e16a6b4 Mon Sep 17 00:00:00 2001 From: Daniel Heppner Date: Thu, 4 Apr 2024 15:12:21 +0800 Subject: [PATCH] fix(nearby-view): don't flash stale data while loading new response --- lib/actions/apiV2.js | 6 +++++- lib/components/viewers/nearby/nearby-view.tsx | 9 +++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/actions/apiV2.js b/lib/actions/apiV2.js index 2a0fe80b0..b69a1840b 100644 --- a/lib/actions/apiV2.js +++ b/lib/actions/apiV2.js @@ -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 + } } } ) diff --git a/lib/components/viewers/nearby/nearby-view.tsx b/lib/components/viewers/nearby/nearby-view.tsx index 6e7bb3b9a..3a0bb1264 100644 --- a/lib/components/viewers/nearby/nearby-view.tsx +++ b/lib/components/viewers/nearby/nearby-view.tsx @@ -75,7 +75,6 @@ function NearbyView({ nearbyViewCoords, radius, setHighlightedLocation, - setLocation, setMainPanelContent, setViewedNearbyCoords, zoomToPlace @@ -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, @@ -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 @@ -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 }