aboutsummaryrefslogtreecommitdiff
path: root/src/screens/profile/CaptionScreen.tsx
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-06-23 17:01:42 -0400
committerIvan Chen <ivan@tagg.id>2021-06-23 17:01:42 -0400
commit66dcf88ab09fbd73e234e209e270e2b31c867247 (patch)
treea1fe16d752ee6c7847311a0e94e69660b37a0592 /src/screens/profile/CaptionScreen.tsx
parentf3651f53af4bf2a7163c82bb8c21bc6ec3940b4e (diff)
Cleanup code, Add support for video tagging
Diffstat (limited to 'src/screens/profile/CaptionScreen.tsx')
-rw-r--r--src/screens/profile/CaptionScreen.tsx92
1 files changed, 62 insertions, 30 deletions
diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx
index 9326ba6a..1b96face 100644
--- a/src/screens/profile/CaptionScreen.tsx
+++ b/src/screens/profile/CaptionScreen.tsx
@@ -28,7 +28,13 @@ import {
SUCCESS_PIC_UPLOAD,
} from '../../constants/strings';
import {MainStackParams} from '../../routes';
-import {patchMoment, postMoment, postMomentTags} from '../../services';
+import {
+ handlePresignedURL,
+ handleVideoUpload,
+ patchMoment,
+ postMoment,
+ postMomentTags,
+} from '../../services';
import {
loadUserMoments,
updateProfileCompletionStage,
@@ -73,7 +79,7 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
moment.moment_url.endsWith('.png') ||
moment.moment_url.endsWith('.PNG')
)
- : route.params.media?.type === 'video';
+ : route.params.media?.isVideo ?? false;
useEffect(() => {
setTags(selectedTags ? selectedTags : []);
@@ -133,35 +139,57 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
const handleShare = async () => {
setLoading(true);
if (moment || !mediaFilename || !title) {
- return;
- }
- const momentResponse = await postMoment(
- mediaFilename,
- mediaUri,
- caption,
- title,
- userId,
- );
- if (!momentResponse) {
handleFailed();
return;
}
- const momentTagResponse = await postMomentTags(
- momentResponse.moment_id,
- formattedTags(),
- );
- if (!momentTagResponse) {
- handleFailed();
- return;
+ let profileCompletionStage;
+ let momentId;
+ // separate upload logic for image/video
+ if (isMediaAVideo) {
+ const presignedURL = await handlePresignedURL(mediaFilename, title);
+ // TOOD: ignoring type error for PoC reason
+ const response: {
+ response_msg: string;
+ response_url: string;
+ moment_id: string;
+ } = handleVideoUpload(
+ {
+ filename: mediaFilename,
+ sourceURL: mediaUri,
+ },
+ presignedURL,
+ );
+ momentId = response.moment_id;
+ } else {
+ const momentResponse = await postMoment(
+ mediaFilename,
+ mediaUri,
+ caption,
+ title,
+ userId,
+ );
+ if (!momentResponse) {
+ handleFailed();
+ return;
+ }
+ profileCompletionStage = momentResponse.profile_completion_stage;
+ momentId = momentResponse.moment_id;
+ }
+ if (momentId) {
+ const momentTagResponse = await postMomentTags(momentId, formattedTags());
+ if (!momentTagResponse) {
+ handleFailed();
+ return;
+ }
}
dispatch(loadUserMoments(userId));
- dispatch(
- updateProfileCompletionStage(momentResponse.profile_completion_stage),
- );
+ if (profileCompletionStage) {
+ dispatch(updateProfileCompletionStage(profileCompletionStage));
+ }
handleSuccess();
};
- const handleDone = async () => {
+ const handleDoneEditing = async () => {
setLoading(true);
if (moment?.moment_id) {
const success = await patchMoment(
@@ -198,7 +226,7 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
title={moment ? 'Done' : 'Share'}
titleStyle={styles.shareButtonTitle}
buttonStyle={styles.button}
- onPress={moment ? handleDone : handleShare}
+ onPress={moment ? handleDoneEditing : handleShare}
/>
</View>
<CaptionScreenHeader
@@ -206,7 +234,11 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
{...{title: moment ? moment.moment_category : title ?? ''}}
/>
{isMediaAVideo ? (
- <Video source={{uri: mediaUri}} style={styles.media} />
+ <Video
+ style={styles.media}
+ source={{uri: mediaUri}}
+ repeat={true}
+ />
) : (
<Image
style={styles.media}
@@ -225,11 +257,11 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
<TouchableOpacity
onPress={() =>
navigation.navigate('TagFriendsScreen', {
- imagePath: moment
- ? moment.moment_url
- : media
- ? media.uri
- : '',
+ media: {
+ filename: mediaFilename ?? '',
+ uri: mediaUri,
+ isVideo: isMediaAVideo,
+ },
selectedTags: tags,
})
}