Skip to content

Commit

Permalink
feat: onNavigateToNextSight callback (MN-504)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakglobant committed Apr 26, 2024
1 parent aef54cf commit 465c143
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
16 changes: 15 additions & 1 deletion packages/camera/src/components/Capture/capture.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ const Capture = forwardRef(({
onReady,
onStartUploadPicture,
onFinishUploadPicture,
onNavigateToNextSight,
orientationBlockerProps,
overlayPathStyles,
primaryColor,
Expand Down Expand Up @@ -352,6 +353,17 @@ const Capture = forwardRef(({
}
}, [setAddDamageStatus, lastAddDamageHelpTimestamp]);

const handleOnFinishUploadPicture = useCallback(async () => {
try {
await onNavigateToNextSight();
} catch (err) {
log([`Error in \`<Capture />\` \`goNextSight()\`: ${err}`], 'err');
} finally {
api.goNextSight();
onFinishUploadPicture();
}
}, [api]);

const handleResetDamageStatus = useCallback(() => {
setAddDamageStatus(AddDamageStatus.IDLE);
setAddDamageParts([]);
Expand Down Expand Up @@ -610,7 +622,7 @@ const Capture = forwardRef(({
onCloseEarly={handleCloseEarlyClick}
onAddDamagePressed={handleAddDamagePressed}
onStartUploadPicture={onStartUploadPicture}
onFinishUploadPicture={onFinishUploadPicture}
onFinishUploadPicture={handleOnFinishUploadPicture}
addDamageParts={addDamageParts}
onResetAddDamageStatus={handleResetDamageStatus}
hideAddDamage={hideAddDamage}
Expand Down Expand Up @@ -857,6 +869,7 @@ Capture.propTypes = {
onComplianceCheckFinish: PropTypes.func,
onComplianceCheckStart: PropTypes.func,
onFinishUploadPicture: PropTypes.func,
onNavigateToNextSight: PropTypes.func,
onPictureTaken: PropTypes.func,
onPictureUploaded: PropTypes.func,
onReady: PropTypes.func,
Expand Down Expand Up @@ -976,6 +989,7 @@ Capture.defaultProps = {
onComplianceCheckFinish: () => { },
onComplianceCheckStart: () => { },
onFinishUploadPicture: () => { },
onNavigateToNextSight: () => { },
onWarningMessage: () => { },
onReady: () => { },
onStartUploadPicture: () => { },
Expand Down
2 changes: 0 additions & 2 deletions packages/camera/src/components/Controls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,10 @@ export default function Controls({
if (action === Actions.sights.ADD_PROCESS_TO_QUEUE) {
if (noOfProcesses < MAX_LIMIT_FOR_PROCESSES && current.index !== (ids.length - 1)) {
onFinishUploadPicture(state, api);
api.goNextSight();
}
} else if (action === Actions.sights.REMOVE_PROCESS_FROM_QUEUE) {
if (noOfProcesses === (MAX_LIMIT_FOR_PROCESSES - 1) && current.index !== (ids.length - 1)) {
onFinishUploadPicture(state, api);
api.goNextSight();
}
}
}, [state.sights.state.process]);
Expand Down
7 changes: 7 additions & 0 deletions website/docs/js/api/components/Capture.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default function Inspector({ inspectionId }) {
onReady={() => setLoading(false)}
onStartUploadPicture={() => setLoading(true)}
onFinishUploadPicture={() => setLoading(false)}
onNavigateToNextSight={onNavigateToNextSight}
onChange={handleChange}
sightIds={Constants.defaultSightIds}
/>
Expand Down Expand Up @@ -93,6 +94,7 @@ export default function Inspector({ inspectionId }) {
onReady={() => setLoading(false)}
onStartUploadPicture={() => setLoading(true)}
onFinishUploadPicture={() => setLoading(false)}
onNavigateToNextSight={onNavigateToNextSight}
onChange={handleChange}
sightIds={Constants.defaultSightIds}
/>
Expand Down Expand Up @@ -468,6 +470,11 @@ const handleStartUploadPicture = (state, api) => console.log('Started uploading

Will call a function when the uploading is finished for every picture.

## onNavigateToNextSight
`PropTypes.func`

Will call a function before navigating to next sight.

```js
const handleFinishUploadPicture = (state, api) => console.log('Finished uploading a picture');
```
Expand Down

0 comments on commit 465c143

Please sign in to comment.