diff options
-rw-r--r-- | src/components/moments/MomentUploadProgressBar.tsx | 16 | ||||
-rw-r--r-- | src/services/MomentService.ts | 20 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/components/moments/MomentUploadProgressBar.tsx b/src/components/moments/MomentUploadProgressBar.tsx index 28fbd8cb..0d84236d 100644 --- a/src/components/moments/MomentUploadProgressBar.tsx +++ b/src/components/moments/MomentUploadProgressBar.tsx @@ -4,6 +4,7 @@ import {View} from 'react-native-animatable'; import {Easing, useSharedValue, withTiming} from 'react-native-reanimated'; import {SafeAreaView} from 'react-native-safe-area-context'; import {useSelector} from 'react-redux'; +import {checkMomentUploadFinished} from '../../services'; import {RootState} from '../../store/rootReducer'; import {MomentUploadStatusType} from '../../types'; import {normalize, SCREEN_WIDTH, StatusBarHeight} from '../../utils'; @@ -22,6 +23,21 @@ const MomentUploadProgressBar: React.FC<MomentUploadProgressBarProps> = if ( momentUploadProgressBar?.status === MomentUploadStatusType.Uploading ) { + const timer = setInterval(async () => { + if (checkMomentUploadFinished(momentUploadProgressBar.momentId)) { + // call upload finished action + } + }, 5 * 1000); + setTimeout(() => { + clearInterval(timer); + }, 5 * 60 * 1000); + } + }, []); + + useEffect(() => { + if ( + momentUploadProgressBar?.status === MomentUploadStatusType.Uploading + ) { progress.value = withTiming(1, { duration: momentUploadProgressBar.originalVideoDuration * 1000, easing: Easing.out(Easing.quad), diff --git a/src/services/MomentService.ts b/src/services/MomentService.ts index 25d44041..2a0d9113 100644 --- a/src/services/MomentService.ts +++ b/src/services/MomentService.ts @@ -1,6 +1,7 @@ import AsyncStorage from '@react-native-community/async-storage'; import RNFetchBlob from 'rn-fetch-blob'; import { + CHECK_MOMENT_UPLOAD_FINISHED_ENDPOINT, MOMENTS_ENDPOINT, MOMENTTAG_ENDPOINT, MOMENT_TAGS_ENDPOINT, @@ -320,3 +321,22 @@ export const handleVideoUpload = async ( } return false; }; + +export const checkMomentUploadFinished = async (momentId: string) => { + try { + const token = await AsyncStorage.getItem('token'); + const response = await fetch( + CHECK_MOMENT_UPLOAD_FINISHED_ENDPOINT + '?moment_id=' + momentId, + { + method: 'GET', + headers: { + Authorization: 'Token ' + token, + }, + }, + ); + return response.status === 200; + } catch (error) { + console.error(error); + return false; + } +}; |