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