NTP-55956 | Pulkit | road distance in address page (#1165)
This commit is contained in:
@@ -33,7 +33,7 @@ import { getForeclosureAmount } from '@actions/feedbackActions';
|
||||
import Geolocation from 'react-native-geolocation-service';
|
||||
import { getAddressLocation } from '@screens/allCases/utils';
|
||||
import { getGeolocationDistance } from '@screens/allCases/allCasesActions';
|
||||
import { debounce } from '@components/utlis/commonFunctions';
|
||||
import { debounce, getDistanceFromLatLonInKm } from '@components/utlis/commonFunctions';
|
||||
import logger from '@components/utlis/logger';
|
||||
|
||||
interface ICaseDetails {
|
||||
@@ -76,6 +76,8 @@ const CollectionCaseDetails: React.FC<ICaseDetails> = (props) => {
|
||||
const pastEscalationCount = Number(escalationData?.pastEscalationCount);
|
||||
const totalEscalationsCount = activeEscalationCount + pastEscalationCount;
|
||||
const watchId = React.useRef<number>(0);
|
||||
const deviceGeolocationCoordinate =
|
||||
useAppSelector((state) => state?.foregroundService?.deviceGeolocationCoordinate) || {};
|
||||
|
||||
useEffect(() => {
|
||||
if (caseId) dispatch(setSelectedCaseId(caseId));
|
||||
@@ -142,18 +144,19 @@ const CollectionCaseDetails: React.FC<ICaseDetails> = (props) => {
|
||||
const debouncedGetDistance = debounce(
|
||||
(params: { source: ICaseItemLatLongData; destinations: ICaseItemLatLongData[] }) => {
|
||||
getGeolocationDistance(params).then((distanceMap) => {
|
||||
if (!distanceMap || distanceMap?.size === 0) {
|
||||
const distanceInKm = getDistanceFromLatLonInKm(
|
||||
params.destinations[0],
|
||||
deviceGeolocationCoordinate
|
||||
);
|
||||
setRoadDistance(distanceInKm);
|
||||
return;
|
||||
}
|
||||
setRoadDistance(distanceMap?.get(params.source.id) || 0);
|
||||
});
|
||||
},
|
||||
2000
|
||||
);
|
||||
watchId.current = Geolocation.watchPosition(
|
||||
(position) => {
|
||||
const source = {
|
||||
id: caseId,
|
||||
latitude: position.coords.latitude,
|
||||
longitude: position.coords.longitude,
|
||||
};
|
||||
const destinations: ICaseItemLatLongData[] = [];
|
||||
const addressLocation = getAddressLocation(caseDetail?.addressLocation);
|
||||
if (addressLocation) {
|
||||
@@ -163,9 +166,22 @@ const CollectionCaseDetails: React.FC<ICaseDetails> = (props) => {
|
||||
longitude: addressLocation?.longitude,
|
||||
});
|
||||
}
|
||||
watchId.current = Geolocation.watchPosition(
|
||||
(position) => {
|
||||
const source = {
|
||||
id: caseId,
|
||||
latitude: position.coords.latitude,
|
||||
longitude: position.coords.longitude,
|
||||
};
|
||||
|
||||
debouncedGetDistance({ source, destinations });
|
||||
},
|
||||
(error) => {
|
||||
const distanceInKm = getDistanceFromLatLonInKm(
|
||||
destinations[0],
|
||||
deviceGeolocationCoordinate
|
||||
);
|
||||
setRoadDistance(distanceInKm);
|
||||
logger({
|
||||
msg: 'Error getting geolocation distance',
|
||||
type: 'error',
|
||||
|
||||
Reference in New Issue
Block a user