diff options
author | Ivan Chen <ivan@tagg.id> | 2021-06-22 19:14:06 -0400 |
---|---|---|
committer | Ivan Chen <ivan@tagg.id> | 2021-06-22 19:14:06 -0400 |
commit | ab13c937f1de947e68df03b443cf9fccb0cd54c9 (patch) | |
tree | 7d3a15e53c37a1420bc60d55db28f21eda0d1d95 /src/components | |
parent | 0561794c67d827c918029f2e06572fd03b4531fd (diff) |
Add alert for gallery and camera
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/moments/Moment.tsx | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/src/components/moments/Moment.tsx b/src/components/moments/Moment.tsx index 9bce6c74..91c14f7d 100644 --- a/src/components/moments/Moment.tsx +++ b/src/components/moments/Moment.tsx @@ -1,5 +1,6 @@ import {useNavigation} from '@react-navigation/native'; import React from 'react'; +import {launchCamera} from 'react-native-image-picker'; import {Alert, StyleProp, StyleSheet, View, ViewStyle} from 'react-native'; import {Text} from 'react-native-animatable'; import {ScrollView, TouchableOpacity} from 'react-native-gesture-handler'; @@ -53,6 +54,15 @@ const Moment: React.FC<MomentProps> = ({ const { 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)); + }; /** * This function opens the ImagePicker, only lets you select video files, * formats the file extension, then makes a call to the server to get the presigned URL, @@ -74,13 +84,9 @@ const Moment: React.FC<MomentProps> = ({ }) .then(async (vid) => { if ('path' in vid) { - if (vid.filename) { - let presignedURL = await handlePresignedURL(vid.filename, title); - console.log('presigned' + JSON.stringify(presignedURL)); - Alert.alert('Uploading...'); - await handleVideoUpload(vid, presignedURL); - Alert.alert('Finish uploading, refreshing moments...'); - dispatch(loadUserMoments(userId)); + console.log(vid); + if (vid.filename && vid.sourceURL) { + uploadVideo(vid.filename, vid.sourceURL); } } }) @@ -158,7 +164,31 @@ const Moment: React.FC<MomentProps> = ({ <PlusIcon width={23} height={23} - onPress={() => navigateToVideoPicker()} + onPress={() => + Alert.alert('Video Upload', 'pick one', [ + { + text: 'gallery', + onPress: navigateToVideoPicker, + }, + { + text: 'camera (simulator will not work)', + onPress: () => + launchCamera( + { + mediaType: 'video', + durationLimit: 60, + videoQuality: 'medium', + }, + (response) => { + console.log(response); + const file = response.assets[0]; + // TODO: not tested + uploadVideo(file.fileName, file.uri); + }, + ), + }, + ]) + } color={'black'} style={styles.horizontalMargin} /> |