@@ -5,7 +5,7 @@ import type {WayPoint} from '@components/MapView/MapViewTypes';
55import { useMemoizedLazyExpensifyIcons } from '@hooks/useLazyAsset' ;
66import useOnyx from '@hooks/useOnyx' ;
77import useTheme from '@hooks/useTheme' ;
8- import { getGPSWaypoints , getTotalGpsTripSegments , isTripStopped as isTripStoppedUtil } from '@libs/GPSDraftDetailsUtils' ;
8+ import { getGPSWaypoints , isTripStopped as isTripStoppedUtil } from '@libs/GPSDraftDetailsUtils' ;
99import CONST from '@src/CONST' ;
1010import ONYXKEYS from '@src/ONYXKEYS' ;
1111import type IconAsset from '@src/types/utils/IconAsset' ;
@@ -28,28 +28,32 @@ function useGPSWaypointMarkers(): WayPoint[] {
2828 ) ;
2929
3030 const gpsWaypoints = getGPSWaypoints ( gpsDraftDetails ) ;
31+ const waypointEntries = Object . entries ( gpsWaypoints ) ;
32+ const lastIndex = waypointEntries . length - 1 ;
33+
34+ return waypointEntries . flatMap ( ( [ key , waypoint ] , index ) : WayPoint [ ] => {
35+ const isStart = index === 0 ;
36+ const isEnd = index === lastIndex ;
37+
38+ if ( isEnd && ! isTripStopped ) {
39+ return [ ] ;
40+ }
3141
32- const gpsWaypointMarkers = Object . entries ( gpsWaypoints ) . map ( ( [ key , waypoint ] , index ) : WayPoint | null => {
33- const tripSegmentsCount = getTotalGpsTripSegments ( gpsDraftDetails ) ;
3442 let icon = DotIndicator ;
35- if ( index === 0 ) {
43+ if ( isStart ) {
3644 icon = DotIndicatorUnfilled ;
37- } else if ( index === tripSegmentsCount * 2 - 1 ) {
45+ } else if ( isEnd ) {
3846 icon = Location ;
39-
40- if ( ! isTripStopped ) {
41- return null ;
42- }
4347 }
4448
45- return {
46- id : key ,
47- coordinate : [ waypoint . lng , waypoint . lat ] ,
48- markerComponent : ( ) : ReactNode => getMarkerComponent ( icon ) ,
49- } ;
49+ return [
50+ {
51+ id : key ,
52+ coordinate : [ waypoint . lng , waypoint . lat ] ,
53+ markerComponent : ( ) : ReactNode => getMarkerComponent ( icon ) ,
54+ } ,
55+ ] ;
5056 } ) ;
51-
52- return gpsWaypointMarkers . filter ( ( waypoint ) : waypoint is WayPoint => ! ! waypoint ) ;
5357}
5458
5559export default useGPSWaypointMarkers ;
0 commit comments