aboutsummaryrefslogtreecommitdiff
path: root/src/store
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-07-28 14:39:05 -0400
committerGitHub <noreply@github.com>2021-07-28 14:39:05 -0400
commit710ce26f2335798623f229469a53c7fe42125058 (patch)
treec8d26e8326d1e0916819ef8aedbf7dc77ded5eb8 /src/store
parent0c4f64a842d052eae917a12089ea9f878501a02a (diff)
parent23afcca0adfb4d0023ed73f489a4874898851971 (diff)
Merge pull request #535 from IvanIFChen/tma1030-progress-bar-for-image-moments
[TMA-1030] Progress Bar for Image Moments
Diffstat (limited to 'src/store')
-rw-r--r--src/store/actions/user.ts84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts
index 1acbb519..14865f25 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)