Skip to content

Commit

Permalink
feat(mosip#625):[Tilak|Adityan] show saving overlay only after 1sec
Browse files Browse the repository at this point in the history
  • Loading branch information
tilak-puli committed Mar 8, 2023
1 parent 79e6627 commit 45e4cc1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
6 changes: 5 additions & 1 deletion machines/openIdBle/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,11 @@ export const requestMachine =
},
},
},
navigatingToHome: {},
navigatingToHome: {
invoke: {
src: 'disconnect',
},
},
savingFailed: {
initial: 'idle',
entry: ['setReceiveLogTypeDiscarded', 'logReceived'],
Expand Down
6 changes: 4 additions & 2 deletions machines/openIdBle/request.typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export interface Typegen0 {
'invokeSrcNameMap': {
advertiseDevice: 'done.invoke.request.waitingForConnection:invocation[0]';
checkBluetoothService: 'done.invoke.request.checkingBluetoothService.checking:invocation[0]';
disconnect: 'done.invoke.request.clearingConnection:invocation[0]';
disconnect:
| 'done.invoke.request.clearingConnection:invocation[0]'
| 'done.invoke.request.reviewing.navigatingToHome:invocation[0]';
exchangeDeviceInfo: 'done.invoke.request.exchangingDeviceInfo:invocation[0]';
monitorConnection: 'done.invoke.request:invocation[0]';
receiveVc: 'done.invoke.request.waitingForVc:invocation[0]';
Expand Down Expand Up @@ -105,7 +107,7 @@ export interface Typegen0 {
| 'DISMISS'
| 'xstate.after(DESTROY_TIMEOUT)#request.clearingConnection';
checkBluetoothService: 'SCREEN_FOCUS' | 'SWITCH_PROTOCOL';
disconnect: '' | 'DISMISS';
disconnect: '' | 'DISMISS' | 'GO_TO_RECEIVED_VC_TAB';
exchangeDeviceInfo: 'RECEIVE_DEVICE_INFO';
monitorConnection: 'xstate.init';
receiveVc: 'EXCHANGE_DONE';
Expand Down
6 changes: 5 additions & 1 deletion screens/Request/ReceiveVcScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ import { useReceiveVcScreen } from './ReceiveVcScreenController';
import { VerifyIdentityOverlay } from '../VerifyIdentityOverlay';
import { MessageOverlay } from '../../components/MessageOverlay';
import { isBLEEnabled } from '../../lib/smartshare';
import { useOverlayVisibleAfterTimeout } from '../../shared/hooks/useOverlayVisibleAfterTimeout';

export const ReceiveVcScreen: React.FC = () => {
const { t } = useTranslation('ReceiveVcScreen');
const controller = useReceiveVcScreen();
const savingOverlayVisible = useOverlayVisibleAfterTimeout(
controller.isAccepting
);

return (
<React.Fragment>
Expand Down Expand Up @@ -104,7 +108,7 @@ export const ReceiveVcScreen: React.FC = () => {
</MessageOverlay>

<MessageOverlay
isVisible={controller.isAccepting}
isVisible={savingOverlayVisible}
message={t('saving', {
vcLabel: controller.vcLabel.plural,
})}
Expand Down
23 changes: 23 additions & 0 deletions shared/hooks/useOverlayVisibleAfterTimeout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useEffect, useState } from 'react';

export const useOverlayVisibleAfterTimeout = (
visibleStart = false,
ms = 1000
) => {
const [visible, setVisible] = useState(false);
const [savingTimeout, setSavingTimeout] = useState(null);

useEffect(() => {
if (visibleStart) {
const timeout = setTimeout(() => {
setVisible(true);
}, ms);
setSavingTimeout(timeout);
} else {
clearTimeout(savingTimeout);
setVisible(false);
}
}, [visibleStart]);

return visible;
};

0 comments on commit 45e4cc1

Please sign in to comment.