Skip to content

Commit

Permalink
Rework useCreateDocumentWithPage.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKScanbot committed Nov 13, 2024
1 parent 75321d8 commit 3e48c17
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/hooks/operations/document/useCreateDocumentWithPage.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import {useCallback, useContext} from 'react';
import {
checkLicense,
errorMessageAlert,
PrimaryRouteNavigationProp,
Screens,
selectImagesFromLibrary,
} from '@utils';
import {ActivityIndicatorContext, DocumentContext} from '@context';
import {useNavigation} from '@react-navigation/native';
import {checkLicense, errorMessageAlert, selectImagesFromLibrary} from '@utils';
import {ActivityIndicatorContext} from '@context';
import {useContinueDocumentScanning} from '@hooks';

import ScanbotSDK from 'react-native-scanbot-sdk';

export function useCreateDocumentWithPage() {
const navigation = useNavigation<PrimaryRouteNavigationProp>();
const {setLoading} = useContext(ActivityIndicatorContext);
const {setDocument} = useContext(DocumentContext);
const continueScanning = useContinueDocumentScanning();

return useCallback(async () => {
try {
Expand All @@ -40,15 +33,14 @@ export function useCreateDocumentWithPage() {
documentDetection: true,
});

/** Add pages if status is OK */
/** Continue scanning */
if (documentResult.status === 'OK') {
setDocument(documentResult);
navigation.navigate(Screens.DOCUMENT_RESULT);
await continueScanning(documentResult.uuid);
}
} catch (e: any) {
errorMessageAlert(e.message);
} finally {
setLoading(false);
}
}, [setDocument, setLoading, navigation]);
}, [setLoading, continueScanning]);
}

0 comments on commit 3e48c17

Please sign in to comment.