diff options
| author | Michael <michael.foiani@gmail.com> | 2021-08-02 11:41:51 -0400 |
|---|---|---|
| committer | Michael <michael.foiani@gmail.com> | 2021-08-02 11:41:51 -0400 |
| commit | e3f8180e24b35eccdb49fe766b9e1fe10c33da3f (patch) | |
| tree | 1841dda83317d0b3ac922691493197aacb036677 /src/store | |
| parent | cf2a5b7294ed3c51898febf393a50108e2b9825d (diff) | |
| parent | 452f3fb44838c367f40e8aa57db2e274a357afd2 (diff) | |
Pull from master
Diffstat (limited to 'src/store')
| -rw-r--r-- | src/store/actions/user.ts | 90 |
1 files changed, 89 insertions, 1 deletions
diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts index 1acbb519..f01e2bac 100644 --- a/src/store/actions/user.ts +++ b/src/store/actions/user.ts @@ -6,6 +6,7 @@ import { handlePresignedURL, handleVideoUpload, loadProfileInfo, + postMoment, postMomentTags, removeBadgesService, sendSuggestedPeopleLinked, @@ -285,6 +286,89 @@ export const suggestedPeopleAnimatedTutorialFinished = } }; +export const handleImageMomentUpload = + ( + imageUri: string, + caption: string, + momentCategory: string, + userId: string, + formattedTags: { + x: number; + y: number; + z: number; + user_id: string; + }[], + ): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => + async (dispatch) => { + try { + const handleError = (reason: string) => { + console.error('Moment video upload failed,', reason); + dispatch({ + type: setMomentUploadProgressBar.type, + payload: { + momentUploadProgressBar: { + ...momentUploadProgressBar, + status: MomentUploadStatusType.Error, + }, + }, + }); + }; + let momentUploadProgressBar: MomentUploadProgressBarType = { + status: MomentUploadStatusType.UploadingToS3, + momentId: '', + originalVideoDuration: 1, // assume upload time for an image is same as a 1s video + }; + // set progress bar as loading + dispatch({ + type: setMomentUploadProgressBar.type, + payload: {momentUploadProgressBar}, + }); + // upload image moment + const momentPostResponse = await postMoment( + imageUri, + caption, + momentCategory, + userId, + ); + if (!momentPostResponse) { + handleError('Moment post failed'); + return; + } + const profileCompletionStage = + momentPostResponse.profile_completion_stage; + const momentId = momentPostResponse.moment_id; + if (!momentId) { + handleError('Unable to parse moment id from moment post response'); + return; + } + // upload moment tags + const momentTagResponse = await postMomentTags(momentId, formattedTags); + if (!momentTagResponse) { + handleError('Moment tag post failed'); + return; + } + if (profileCompletionStage) { + dispatch(updateProfileCompletionStage(profileCompletionStage)); + } else { + console.error( + 'failed to parse profile complete stage from moment post response', + ); + } + // mark progress bar state as done + dispatch({ + type: setMomentUploadProgressBar.type, + payload: { + momentUploadProgressBar: { + ...momentUploadProgressBar, + status: MomentUploadStatusType.Done, + }, + }, + }); + } catch (error) { + console.log(error); + } + }; + /** * state is now UploadingToS3: * - get presigned url (backend creates the moment object) @@ -296,6 +380,7 @@ export const handleVideoMomentUpload = ( videoUri: string, videoLength: number, + caption: string, momentCategory: string, formattedTags: { x: number; @@ -329,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; |
