diff options
author | Ivan Chen <ivan@tagg.id> | 2021-06-23 13:37:39 -0400 |
---|---|---|
committer | Ivan Chen <ivan@tagg.id> | 2021-06-23 13:37:39 -0400 |
commit | 25d1a6514c9df784df27d22da648340ae018c1f8 (patch) | |
tree | 57bfc2f0b75a38adc9eeb678d37e78214868a5b8 /src | |
parent | 4ecc4525738dc8a56c9f37a05d0870e54cfa5be9 (diff) |
Minor logic cleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/components/moments/Moment.tsx | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/components/moments/Moment.tsx b/src/components/moments/Moment.tsx index 91c14f7d..cd76f36c 100644 --- a/src/components/moments/Moment.tsx +++ b/src/components/moments/Moment.tsx @@ -55,13 +55,17 @@ const Moment: React.FC<MomentProps> = ({ user: {userId}, } = useSelector((state: RootState) => state.user); - const uploadVideo = async (filename: string, filePath: string) => { - let presignedURL = await handlePresignedURL(filename, title); - console.log('presigned' + JSON.stringify(presignedURL)); - Alert.alert('Uploading...'); - await handleVideoUpload(filename, filePath, presignedURL); - Alert.alert('Finish uploading, refreshing moments...'); - dispatch(loadUserMoments(userId)); + const uploadVideo = async (filePath: string) => { + const randHash = Math.random().toString(36).substring(7); + const filename = `poc_${randHash}.mov`; + const presignedURL = await handlePresignedURL(filename, title); + if (presignedURL) { + console.log('presigned' + JSON.stringify(presignedURL)); + Alert.alert('Upload begin in background...'); + await handleVideoUpload(filename, filePath, presignedURL); + Alert.alert('Finish uploading, refreshing moments...'); + dispatch(loadUserMoments(userId)); + } }; /** * This function opens the ImagePicker, only lets you select video files, @@ -86,7 +90,7 @@ const Moment: React.FC<MomentProps> = ({ if ('path' in vid) { console.log(vid); if (vid.filename && vid.sourceURL) { - uploadVideo(vid.filename, vid.sourceURL); + uploadVideo(vid.sourceURL); } } }) @@ -177,13 +181,16 @@ const Moment: React.FC<MomentProps> = ({ { mediaType: 'video', durationLimit: 60, - videoQuality: 'medium', }, (response) => { console.log(response); - const file = response.assets[0]; - // TODO: not tested - uploadVideo(file.fileName, file.uri); + if ( + response.assets && + response.assets.length !== 0 && + response.assets[0].uri + ) { + uploadVideo(response.assets[0].uri); + } }, ), }, |