TP-25164 location api fix (#240)

* TP-25164 location api fix

* TP-25164 fix error message

* TP-25164 warn eslint

* fix error message TP-25164

* remove gibberish TP-25164
This commit is contained in:
Aman Sethi
2023-04-13 19:34:03 +05:30
committed by GitHub Enterprise
parent 75ae08058e
commit 8f5bf6dc5a
4 changed files with 43 additions and 15 deletions

View File

@@ -22,5 +22,6 @@
"react-native"
],
"rules": {
"@typescript-eslint/strict-boolean-expressions": 1
}
}

View File

@@ -85,7 +85,6 @@ const askForPermissions = async (
};
const App = () => {
useNativeButtons();
const [permissions, setPermissions] = React.useState(true);
const [isGlobalDocumentMapLoaded, setIsGlobalDocumentMapLoaded] = React.useState(false);

View File

@@ -44,6 +44,7 @@ import VKYCFullScreen from './src/screens/caseDetails/VKYCFullScreen';
import { verifyGoogleSignIn } from './src/action/authActions';
import { Linking } from 'react-native';
import { getParamsObject } from './src/components/utlis/commonFunctions';
import useNativeButtons from './src/hooks/useNativeButton';
const ANIMATION_DURATION = 300;
@@ -59,6 +60,7 @@ export enum PageRouteEnum {
}
const ProtectedRouter = () => {
useNativeButtons();
const user = useSelector(
(state: RootState) => state.user,
);

View File

@@ -1,13 +1,18 @@
import React, { useEffect, useRef, useState } from 'react';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { BackHandler, AppState, AppStateStatus } from 'react-native';
import { GeoCoordinates } from 'react-native-geolocation-service';
import { useAppSelector } from '.';
import { CLICKSTREAM_EVENT_NAMES } from '../common/Constants';
import { CaptureGeolocation } from '../components/form/services/geoLocation.service';
import { logError } from '../components/utlis/errorUtils';
import { addClickstreamEvent } from '../services/clickstreamEventService';
import { RootState } from '../store/store';
import { sendLocationToServer } from './capturingApi';
const THREE_MINUTES = 3 * 60 * 1000;
const useNativeButtons = () => {
const {
user: { isLoggedIn },
} = useAppSelector((state: RootState) => state);
const appState = useRef(AppState.currentState);
const intervalRef = useRef(0);
@@ -16,15 +21,22 @@ const useNativeButtons = () => {
return false;
};
const fetchAndSendToserver = async () => {
const location = await CaptureGeolocation.fetchLocation(
'FETCH_LOCATION',
0,
);
if (location) {
sendLocationToServer(location);
}
};
const fetchAndSendToserver = useCallback(
async () => {
if(!isLoggedIn) {
return;
}
const location = await CaptureGeolocation.fetchLocation(
'FETCH_LOCATION',
0,
);
if (location) {
await sendLocationToServer(location);
}
},
[isLoggedIn],
)
const handleAppStateChange = async (nextAppState: AppStateStatus) => {
if (
@@ -32,7 +44,7 @@ const useNativeButtons = () => {
nextAppState === 'active'
) {
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.AV_APP_FOREGROUND);
fetchAndSendToserver();
await fetchAndSendToserver();
}
if (
appState.current === 'active' &&
@@ -43,6 +55,16 @@ const useNativeButtons = () => {
appState.current = nextAppState;
};
useEffect(() => {
if(isLoggedIn) {
(async () => {
await fetchAndSendToserver();
})().catch(e => {
logError(e, 'Error during login background location sending');
});
}
}, [isLoggedIn, fetchAndSendToserver]);
useEffect(() => {
const backHandler = BackHandler.addEventListener(
'hardwareBackPress',
@@ -52,9 +74,13 @@ const useNativeButtons = () => {
'change',
handleAppStateChange,
);
fetchAndSendToserver();
fetchAndSendToserver().catch(e => {
logError(e, 'Error during background location sending.');
});
intervalRef.current = setInterval(() => {
fetchAndSendToserver();
fetchAndSendToserver().catch(e => {
logError(e, 'Error during background location sending.');
});
}, THREE_MINUTES);
return () => {