From 8181eacc003342fc6bff649b8d1bd793a88efee5 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 22 Jul 2021 18:13:08 -0400 Subject: Handle error case for displaying alert, Add logic to auto reload --- src/components/moments/MomentUploadProgressBar.tsx | 25 ++++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src/components') diff --git a/src/components/moments/MomentUploadProgressBar.tsx b/src/components/moments/MomentUploadProgressBar.tsx index 742c403b..afda16e2 100644 --- a/src/components/moments/MomentUploadProgressBar.tsx +++ b/src/components/moments/MomentUploadProgressBar.tsx @@ -10,6 +10,7 @@ import { import {SafeAreaView} from 'react-native-safe-area-context'; import {useDispatch, useSelector} from 'react-redux'; import {checkMomentUploadFinished} from '../../services'; +import {loadUserMoments} from '../../store/actions'; import {setMomentUploadProgressBar} from '../../store/reducers'; import {RootState} from '../../store/rootReducer'; import {MomentUploadStatusType} from '../../types'; @@ -21,6 +22,9 @@ interface MomentUploadProgressBarProps {} const MomentUploadProgressBar: React.FC = ({}) => { const dispatch = useDispatch(); + const {userId: loggedInUserId} = useSelector( + (state: RootState) => state.user.user, + ); const {momentUploadProgressBar} = useSelector( (state: RootState) => state.user, ); @@ -72,17 +76,19 @@ const MomentUploadProgressBar: React.FC = }, 5 * 1000); // timeout if takes longer than 1 minute to process setTimeout(() => { - console.error('Check for done processing timed out'); clearInterval(timer); - dispatch({ - type: setMomentUploadProgressBar.type, - payload: { - momentUploadProgressBar: { - ...momentUploadProgressBar, - status: MomentUploadStatusType.Error, + if (!doneProcessing) { + console.error('Check for done processing timed out'); + dispatch({ + type: setMomentUploadProgressBar.type, + payload: { + momentUploadProgressBar: { + ...momentUploadProgressBar, + status: MomentUploadStatusType.Error, + }, }, - }, - }); + }); + } }, 60 * 1000); return () => clearInterval(timer); } @@ -109,6 +115,7 @@ const MomentUploadProgressBar: React.FC = progress.value = 0; // clear this component after a duration setTimeout(() => { + dispatch(loadUserMoments(loggedInUserId)); dispatch({ type: setMomentUploadProgressBar.type, payload: { -- cgit v1.2.3-70-g09d2