diff options
Diffstat (limited to 'src/screens/profile/CaptionScreen.tsx')
-rw-r--r-- | src/screens/profile/CaptionScreen.tsx | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx index 7f77bdca..6ba1791c 100644 --- a/src/screens/profile/CaptionScreen.tsx +++ b/src/screens/profile/CaptionScreen.tsx @@ -34,14 +34,9 @@ import { } from '../../constants/strings'; import * as RootNavigation from '../../RootNavigation'; import {MainStackParams} from '../../routes'; +import {patchMoment, postMoment, postMomentTags} from '../../services'; import { - handlePresignedURL, - handleVideoUpload, - patchMoment, - postMoment, - postMomentTags, -} from '../../services'; -import { + handleVideoMomentUpload, loadUserMoments, updateProfileCompletionStage, } from '../../store/actions'; @@ -76,6 +71,8 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => { const [tags, setTags] = useState<MomentTagType[]>([]); const [taggedUsersText, setTaggedUsersText] = useState(''); const [momentCategory, setMomentCategory] = useState<string | undefined>(); + // only used for upload purposes, undefined for editing is fine + const videoDuration = moment ? undefined : route.params.media!.videoDuration; const mediaUri = moment ? moment.moment_url : route.params.media!.uri; // TODO: change this once moment refactor is done const isMediaAVideo = moment @@ -133,11 +130,7 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => { navigation.popToTop(); RootNavigation.navigate('ProfileTab'); setTimeout(() => { - if (isMediaAVideo) { - Alert.alert( - 'Beautiful, the Moment was uploaded successfully! Check back in a bit and refresh to see it!', - ); - } else { + if (!isMediaAVideo) { Alert.alert(SUCCESS_PIC_UPLOAD); } }, 500); @@ -166,20 +159,20 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => { return; } let profileCompletionStage; - let momentId; // separate upload logic for image/video if (isMediaAVideo) { - const presignedURLResponse = await handlePresignedURL(momentCategory); - if (!presignedURLResponse) { - handleFailed(); - return; - } - momentId = presignedURLResponse.moment_id; - const fileHash = presignedURLResponse.response_url.fields.key; - if (fileHash !== null && fileHash !== '' && fileHash !== undefined) { - await handleVideoUpload(mediaUri, presignedURLResponse); + if (videoDuration) { + dispatch( + handleVideoMomentUpload( + mediaUri, + videoDuration, + momentCategory, + formattedTags(), + ), + ); } else { handleFailed(); + return; } } else { const momentResponse = await postMoment( @@ -193,13 +186,16 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => { return; } profileCompletionStage = momentResponse.profile_completion_stage; - momentId = momentResponse.moment_id; - } - if (momentId) { - const momentTagResponse = await postMomentTags(momentId, formattedTags()); - if (!momentTagResponse) { - handleFailed(); - return; + const momentId = momentResponse.moment_id; + if (momentId) { + const momentTagResponse = await postMomentTags( + momentId, + formattedTags(), + ); + if (!momentTagResponse) { + handleFailed(); + return; + } } } if (!isMediaAVideo) { @@ -325,6 +321,7 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => { media: { uri: mediaUri, isVideo: isMediaAVideo, + videoDuration, }, selectedTags: tags, }) |