Skip to content

Commit

Permalink
play sound fix
Browse files Browse the repository at this point in the history
  • Loading branch information
allroundexperts committed Jun 26, 2024
1 parent 283d30f commit 9fe0582
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
37 changes: 20 additions & 17 deletions src/components/LocationPermissionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ type LocationPermissionModalProps = {

/** Should start the permission flow? */
startPermissionFlow: boolean;

/** Reset the permission flow */
resetPermissionFlow: () => void;
};

function LocationPermissionModal({startPermissionFlow, onDeny, onGrant}: LocationPermissionModalProps) {
function LocationPermissionModal({startPermissionFlow, resetPermissionFlow, onDeny, onGrant}: LocationPermissionModalProps) {
const [hasError, setHasError] = useState(false);
const [showModal, setShowModal] = useState(false);

Expand All @@ -37,35 +40,35 @@ function LocationPermissionModal({startPermissionFlow, onDeny, onGrant}: Locatio
}

setShowModal(true);
setHasError(status === RESULTS.BLOCKED || status === RESULTS.DENIED);
setHasError(status === RESULTS.BLOCKED);
});
// eslint-disable-next-line react-hooks/exhaustive-deps -- We only want to run this effect when startPermissionFlow changes
}, [startPermissionFlow]);

const errorHandler = (cb: () => void) => () => {
if (hasError && Linking.openSettings) {
Linking.openSettings();
setShowModal(false);
setHasError(false);
resetPermissionFlow();
return;
}
cb();
};

const onConfirm = errorHandler(() => {
requestLocationPermission()
.then((status) => {
if (status === RESULTS.GRANTED || status === RESULTS.LIMITED) {
onGrant();
} else {
onDeny(status);
}
})
.catch(() => {
onDeny(RESULTS.BLOCKED);
})
.finally(() => {
setShowModal(false);
setHasError(false);
});
requestLocationPermission().then((status) => {
if (status === RESULTS.GRANTED || status === RESULTS.LIMITED) {
onGrant();
} else if (status === RESULTS.BLOCKED) {
setHasError(true);
return;
} else {
onDeny(status);
}
setShowModal(false);
setHasError(false);
});
});

const onCancel = () => {
Expand Down
9 changes: 8 additions & 1 deletion src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ type MoneyRequestConfirmationListProps = MoneyRequestConfirmationListOnyxProps &

/** The action to take */
action?: IOUAction;

/** Should play sound on confirmation */
shouldPlaySound?: boolean;
};

type MoneyRequestConfirmationListItem = Participant | ReportUtils.OptionData;
Expand Down Expand Up @@ -204,6 +207,7 @@ function MoneyRequestConfirmationList({
action = CONST.IOU.ACTION.CREATE,
currencyList,
shouldDisplayReceipt = false,
shouldPlaySound = true,
}: MoneyRequestConfirmationListProps) {
const policy = policyReal ?? policyDraft;
const policyCategories = policyCategoriesReal ?? policyCategoriesDraft;
Expand Down Expand Up @@ -677,7 +681,9 @@ function MoneyRequestConfirmationList({
return;
}

playSound(SOUNDS.DONE);
if (shouldPlaySound) {
playSound(SOUNDS.DONE);
}
setDidConfirm(true);
onConfirm?.(selectedParticipants);
} else {
Expand Down Expand Up @@ -711,6 +717,7 @@ function MoneyRequestConfirmationList({
isDistanceRequestWithPendingRoute,
iouAmount,
onConfirm,
shouldPlaySound,
],
);

Expand Down
2 changes: 2 additions & 0 deletions src/pages/iou/request/step/IOURequestStepConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ function IOURequestStepConfirmation({
{gpsRequired && (
<LocationPermissionModal
startPermissionFlow={startLocationPermissionFlow}
resetPermissionFlow={() => setStartLocationPermissionFlow(false)}
onGrant={() => createTransaction(selectedParticipantList, true)}
onDeny={() => createTransaction(selectedParticipantList, false)}
/>
Expand Down Expand Up @@ -621,6 +622,7 @@ function IOURequestStepConfirmation({
shouldShowSmartScanFields={isMovingTransactionFromTrackExpense ? transaction?.amount !== 0 : requestType !== CONST.IOU.REQUEST_TYPE.SCAN}
action={action}
payeePersonalDetails={payeePersonalDetails}
shouldPlaySound={!gpsRequired}
/>
</View>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ function getLocationPermission(): Promise<PermissionStatus> {
if (navigator.geolocation) {
navigator.permissions.query({name: 'geolocation'}).then((result) => {
if (result.state === 'prompt') {
resolve(RESULTS.UNAVAILABLE);
resolve(RESULTS.DENIED);
return;
}
resolve(result.state === 'granted' ? RESULTS.GRANTED : RESULTS.DENIED);
resolve(result.state === 'granted' ? RESULTS.GRANTED : RESULTS.BLOCKED);
});
} else {
resolve(RESULTS.UNAVAILABLE);
Expand Down

0 comments on commit 9fe0582

Please sign in to comment.