11import React from 'react' ;
22import { View } from 'react-native' ;
33import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription' ;
4- import { useProductTrainingContext } from '@components/ProductTrainingContext' ;
54import ScrollView from '@components/ScrollView' ;
65import Text from '@components/Text' ;
7- import EducationalTooltip from '@components/Tooltip/EducationalTooltip' ;
86import { useMemoizedLazyExpensifyIcons } from '@hooks/useLazyAsset' ;
97import useLocalize from '@hooks/useLocalize' ;
108import useOnyx from '@hooks/useOnyx' ;
119import useStyleUtils from '@hooks/useStyleUtils' ;
1210import useThemeStyles from '@hooks/useThemeStyles' ;
13- import useWindowDimensions from '@hooks/useWindowDimensions' ;
1411import DistanceRequestUtils from '@libs/DistanceRequestUtils' ;
1512import variables from '@styles/variables' ;
16- import CONST from '@src/CONST ' ;
13+ import { isTripCaptured as isTripCapturedUtil } from '@src/libs/GPSDraftDetailsUtils ' ;
1714import ONYXKEYS from '@src/ONYXKEYS' ;
18- import { isTrackingSelector } from '@src/selectors/GPSDraftDetails' ;
1915import type { Unit } from '@src/types/onyx/Policy' ;
2016
2117type WaypointsProps = {
@@ -34,29 +30,42 @@ function Waypoints({unit, isInLandscapeMode}: WaypointsProps) {
3430
3531 const icons = useMemoizedLazyExpensifyIcons ( [ 'Location' , 'Crosshair' , 'DotIndicatorUnfilled' ] ) ;
3632
37- const tripInProgressOrStopped = ( gpsDraftDetails ?. gpsPoints ?. length ?? 0 ) > 0 || gpsDraftDetails ?. isTracking ;
33+ // eslint-disable-next-line rulesdir/no-negated-variables
34+ const tripNotInitialized = ( gpsDraftDetails ?. gpsPoints ?. length ?? 0 ) === 0 && ! gpsDraftDetails ?. isTracking ;
3835
39- if ( ! tripInProgressOrStopped ) {
36+ if ( tripNotInitialized ) {
4037 return null ;
4138 }
4239
43- const isTripCaptured = ! gpsDraftDetails ?. isTracking && ( gpsDraftDetails ?. gpsPoints ?. length ?? 0 ) > 0 ;
40+ const isTripCaptured = isTripCapturedUtil ( gpsDraftDetails ) ;
4441
4542 const shouldShowLoadingEndAddress = isTripCaptured && ! gpsDraftDetails ?. endAddress ?. value ;
46- const shouldShowLoadingStartAddress = gpsDraftDetails ?. isTracking && ! gpsDraftDetails ?. startAddress ?. value ;
43+ const shouldShowLoadingStartAddress = ! gpsDraftDetails ?. startAddress ?. value ;
4744
4845 const distance = DistanceRequestUtils . convertDistanceUnit ( gpsDraftDetails ?. distanceInMeters ?? 0 , unit ) . toFixed ( 1 ) ;
4946
5047 const Wrapper = isInLandscapeMode ? ScrollView : View ;
5148
49+ const getEndAddressTitle = ( ) => {
50+ if ( isTripCaptured ) {
51+ return gpsDraftDetails ?. endAddress ?. value ;
52+ }
53+
54+ if ( shouldShowLoadingEndAddress ) {
55+ return '...' ;
56+ }
57+
58+ return translate ( 'gps.trackingDistance' ) ;
59+ } ;
60+
5261 return (
5362 < Wrapper style = { [ styles . pt2 , styles . pb4 ] } >
5463 < MenuItemWithTopDescription
5564 interactive = { false }
5665 description = { translate ( 'common.distance' ) }
5766 titleComponent = {
5867 < Text style = { [ styles . iouAmountTextInput , styles . textXLarge , styles . colorMuted , styles . ml3 ] } >
59- < Text style = { [ styles . iouAmountTextInput , styles . textXLarge , ! tripInProgressOrStopped && styles . colorMuted ] } > { distance } </ Text >
68+ < Text style = { [ styles . iouAmountTextInput , styles . textXLarge ] } > { distance } </ Text >
6069 { ` ${ unit } ` }
6170 </ Text >
6271 }
@@ -65,58 +74,28 @@ function Waypoints({unit, isInLandscapeMode}: WaypointsProps) {
6574 shouldIconUseAutoWidthStyle
6675 descriptionTextStyle = { StyleUtils . getFontSizeStyle ( variables . fontSizeLabel ) }
6776 />
68- { ( ! ! gpsDraftDetails ?. isTracking || ! ! gpsDraftDetails ?. startAddress ?. value ) && (
69- < GPSTooltip >
70- < View >
71- < MenuItemWithTopDescription
72- interactive = { false }
73- description = { translate ( 'gps.start' ) }
74- shouldShowLoadingSpinnerIcon = { shouldShowLoadingStartAddress }
75- title = { shouldShowLoadingStartAddress ? '...' : gpsDraftDetails ?. startAddress ?. value }
76- icon = { icons . DotIndicatorUnfilled }
77- style = { styles . pv3 }
78- shouldIconUseAutoWidthStyle
79- />
80- </ View >
81- </ GPSTooltip >
82- ) }
83- { isTripCaptured || gpsDraftDetails ?. isTracking ? (
84- < MenuItemWithTopDescription
85- interactive = { false }
86- description = { translate ( 'gps.stop' ) }
87- shouldShowLoadingSpinnerIcon = { shouldShowLoadingEndAddress }
88- // eslint-disable-next-line no-nested-ternary
89- title = { gpsDraftDetails ?. isTracking ? translate ( 'gps.trackingDistance' ) : shouldShowLoadingEndAddress ? '...' : gpsDraftDetails ?. endAddress ?. value }
90- icon = { icons . Location }
91- style = { styles . pv3 }
92- shouldIconUseAutoWidthStyle
93- />
94- ) : null }
77+
78+ < MenuItemWithTopDescription
79+ interactive = { false }
80+ description = { translate ( 'gps.start' ) }
81+ shouldShowLoadingSpinnerIcon = { shouldShowLoadingStartAddress }
82+ title = { shouldShowLoadingStartAddress ? '...' : gpsDraftDetails ?. startAddress ?. value }
83+ icon = { icons . DotIndicatorUnfilled }
84+ style = { styles . pv3 }
85+ shouldIconUseAutoWidthStyle
86+ />
87+
88+ < MenuItemWithTopDescription
89+ interactive = { false }
90+ description = { translate ( 'gps.stop' ) }
91+ shouldShowLoadingSpinnerIcon = { shouldShowLoadingEndAddress }
92+ title = { getEndAddressTitle ( ) }
93+ icon = { icons . Location }
94+ style = { styles . pv3 }
95+ shouldIconUseAutoWidthStyle
96+ />
9597 </ Wrapper >
9698 ) ;
9799}
98100
99101export default Waypoints ;
100-
101- const GPS_TOOLTIP_HORIZONTAL_PADDING = 40 ;
102-
103- function GPSTooltip ( { children} : React . PropsWithChildren ) {
104- const [ isTracking = false ] = useOnyx ( ONYXKEYS . GPS_DRAFT_DETAILS , { selector : isTrackingSelector } ) ;
105-
106- const styles = useThemeStyles ( ) ;
107- const { windowWidth} = useWindowDimensions ( ) ;
108-
109- const { renderProductTrainingTooltip, shouldShowProductTrainingTooltip} = useProductTrainingContext ( CONST . PRODUCT_TRAINING_TOOLTIP_NAMES . GPS_TOOLTIP , ! ! isTracking ) ;
110-
111- return (
112- < EducationalTooltip
113- wrapperStyle = { styles . productTrainingTooltipWrapper }
114- shiftVertical = { - 12 }
115- maxWidth = { windowWidth - GPS_TOOLTIP_HORIZONTAL_PADDING }
116- renderTooltipContent = { renderProductTrainingTooltip }
117- shouldRender = { shouldShowProductTrainingTooltip }
118- >
119- { children }
120- </ EducationalTooltip >
121- ) ;
122- }
0 commit comments