aboutsummaryrefslogtreecommitdiff
path: root/src/components/moments/Moment.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/moments/Moment.tsx')
-rw-r--r--src/components/moments/Moment.tsx54
1 files changed, 44 insertions, 10 deletions
diff --git a/src/components/moments/Moment.tsx b/src/components/moments/Moment.tsx
index 34b2c7ea..e4acebdf 100644
--- a/src/components/moments/Moment.tsx
+++ b/src/components/moments/Moment.tsx
@@ -5,6 +5,7 @@ import {Text} from 'react-native-animatable';
import {ScrollView, TouchableOpacity} from 'react-native-gesture-handler';
import ImagePicker from 'react-native-image-crop-picker';
import LinearGradient from 'react-native-linear-gradient';
+import {useDispatch, useSelector} from 'react-redux';
import DeleteIcon from '../../assets/icons/delete-logo.svg';
import DownIcon from '../../assets/icons/down_icon.svg';
import BigPlusIcon from '../../assets/icons/plus-icon-white.svg';
@@ -16,6 +17,8 @@ import {
handlePresignedURL,
handleVideoUpload,
} from '../../services/MomentService';
+import {loadUserMoments} from '../../store/actions';
+import {RootState} from '../../store/rootReducer';
import {MomentType, ScreenType} from '../../types';
import {normalize, SCREEN_WIDTH} from '../../utils';
import MomentTile from './MomentTile';
@@ -46,6 +49,23 @@ const Moment: React.FC<MomentProps> = ({
externalStyles,
}) => {
const navigation = useNavigation();
+ const dispatch = useDispatch();
+ const {
+ user: {userId},
+ } = useSelector((state: RootState) => state.user);
+
+ 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,
* formats the file extension, then makes a call to the server to get the presigned URL,
@@ -62,21 +82,16 @@ const Moment: React.FC<MomentProps> = ({
'Screenshots',
'UserLibrary',
],
- width: 580,
- height: 580,
- cropping: false,
cropperToolbarTitle: 'select a video',
mediaType: 'video',
})
.then(async (vid) => {
if ('path' in vid) {
- let fileName = vid.filename || '';
- if (fileName.endsWith('.heic') || fileName.endsWith('.HEIC')) {
- fileName = fileName.split('.')[0] + '.jpg';
+ console.log(vid);
+ // vid.path is compressed mp4, vid.sourceURL is uncompressed original
+ if (vid.path) {
+ uploadVideo(vid.path);
}
- let presignedURL = await handlePresignedURL(fileName, title);
- console.log('presigned' + JSON.stringify(presignedURL));
- handleVideoUpload(vid, presignedURL);
}
})
.catch((err) => {
@@ -153,7 +168,26 @@ 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: () =>
+ ImagePicker.openCamera({
+ mediaType: 'video',
+ }).then((vid) => {
+ console.log(vid);
+ if (vid.path) {
+ uploadVideo(vid.path);
+ }
+ }),
+ },
+ ])
+ }
color={'black'}
style={styles.horizontalMargin}
/>