From ee8ccd2b48dee19c5526c1fccb613b718c0cf759 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Tue, 27 Jul 2021 16:52:32 -0400 Subject: Add image moment upload action --- src/screens/profile/CaptionScreen.tsx | 68 +++++++++++------------------------ 1 file changed, 20 insertions(+), 48 deletions(-) (limited to 'src/screens/profile') diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx index 3ee0bd5b..f3b8788b 100644 --- a/src/screens/profile/CaptionScreen.tsx +++ b/src/screens/profile/CaptionScreen.tsx @@ -36,6 +36,7 @@ import * as RootNavigation from '../../RootNavigation'; import {MainStackParams} from '../../routes'; import {patchMoment, postMoment, postMomentTags} from '../../services'; import { + handleImageMomentUpload, handleVideoMomentUpload, loadUserMoments, updateProfileCompletionStage, @@ -138,11 +139,6 @@ const CaptionScreen: React.FC = ({route, navigation}) => { // then switch to the profile tab navigation.popToTop(); RootNavigation.navigate('ProfileTab'); - setTimeout(() => { - if (!isMediaAVideo) { - Alert.alert(SUCCESS_PIC_UPLOAD); - } - }, 500); } else { // if editing, simply go back to profile screen navigation.navigate('Profile', { @@ -167,53 +163,29 @@ const CaptionScreen: React.FC = ({route, navigation}) => { handleFailed(true); return; } - let profileCompletionStage; - // separate upload logic for image/video if (isMediaAVideo) { - if (videoDuration) { - dispatch( - handleVideoMomentUpload( - mediaUri, - videoDuration, - momentCategory, - formattedTags(), - ), - ); - } else { - handleFailed(); - return; - } - } else { - const momentResponse = await postMoment( - mediaUri, - caption, - momentCategory, - userId, + dispatch( + handleVideoMomentUpload( + mediaUri, + videoDuration ?? 30, + momentCategory, + formattedTags(), + ), ); - if (!momentResponse) { - handleFailed(); - return; - } - profileCompletionStage = momentResponse.profile_completion_stage; - const momentId = momentResponse.moment_id; - if (momentId) { - const momentTagResponse = await postMomentTags( - momentId, + } else { + dispatch( + handleImageMomentUpload( + mediaUri, + caption, + momentCategory, + userId, formattedTags(), - ); - if (!momentTagResponse) { - handleFailed(); - return; - } - } - } - if (!isMediaAVideo) { - dispatch(loadUserMoments(userId)); - } - if (profileCompletionStage) { - dispatch(updateProfileCompletionStage(profileCompletionStage)); + ), + ); } - handleSuccess(); + setTimeout(() => { + handleSuccess(); + }, 500); }; const handleSubmitEditChanges = async () => { -- cgit v1.2.3-70-g09d2 From 23afcca0adfb4d0023ed73f489a4874898851971 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Tue, 27 Jul 2021 17:43:31 -0400 Subject: Lint --- src/screens/profile/CaptionScreen.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/screens/profile') diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx index f3b8788b..66106a6f 100644 --- a/src/screens/profile/CaptionScreen.tsx +++ b/src/screens/profile/CaptionScreen.tsx @@ -30,16 +30,14 @@ import { ERROR_NO_MOMENT_CATEGORY, ERROR_SOMETHING_WENT_WRONG_REFRESH, ERROR_UPLOAD, - SUCCESS_PIC_UPLOAD, } from '../../constants/strings'; import * as RootNavigation from '../../RootNavigation'; import {MainStackParams} from '../../routes'; -import {patchMoment, postMoment, postMomentTags} from '../../services'; +import {patchMoment} from '../../services'; import { handleImageMomentUpload, handleVideoMomentUpload, loadUserMoments, - updateProfileCompletionStage, } from '../../store/actions'; import {RootState} from '../../store/rootReducer'; import {MomentTagType} from '../../types'; -- cgit v1.2.3-70-g09d2 From 4170b75030ff07339a5d59a32206dc6e2d843ed7 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Tue, 27 Jul 2021 15:51:17 -0400 Subject: Accept caption --- src/screens/profile/CaptionScreen.tsx | 1 + src/services/MomentService.ts | 6 +++++- src/store/actions/user.ts | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src/screens/profile') diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx index 66106a6f..d329c589 100644 --- a/src/screens/profile/CaptionScreen.tsx +++ b/src/screens/profile/CaptionScreen.tsx @@ -166,6 +166,7 @@ const CaptionScreen: React.FC = ({route, navigation}) => { handleVideoMomentUpload( mediaUri, videoDuration ?? 30, + caption, momentCategory, formattedTags(), ), diff --git a/src/services/MomentService.ts b/src/services/MomentService.ts index 3a677ccc..0292f9ea 100644 --- a/src/services/MomentService.ts +++ b/src/services/MomentService.ts @@ -223,7 +223,10 @@ export const deleteMomentTag = async (moment_tag_id: string) => { * @param value: string | undefined * @returns a PresignedURLResponse object */ -export const handlePresignedURL = async (momentCategory: string) => { +export const handlePresignedURL = async ( + caption: string, + momentCategory: string, +) => { try { // TODO: just a random filename for video poc, we should not need to once complete const randHash = Math.random().toString(36).substring(7); @@ -236,6 +239,7 @@ export const handlePresignedURL = async (momentCategory: string) => { }, body: JSON.stringify({ filename, + caption: caption, category: momentCategory, }), }); diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts index 14865f25..f01e2bac 100644 --- a/src/store/actions/user.ts +++ b/src/store/actions/user.ts @@ -380,6 +380,7 @@ export const handleVideoMomentUpload = ( videoUri: string, videoLength: number, + caption: string, momentCategory: string, formattedTags: { x: number; @@ -413,7 +414,10 @@ export const handleVideoMomentUpload = payload: {momentUploadProgressBar}, }); // get a presigned url for the video - const presignedURLResponse = await handlePresignedURL(momentCategory); + const presignedURLResponse = await handlePresignedURL( + caption, + momentCategory, + ); if (!presignedURLResponse) { handleError('Presigned URL failed'); return; -- cgit v1.2.3-70-g09d2