diff options
Diffstat (limited to 'src/screens/profile/CaptionScreen.tsx')
-rw-r--r-- | src/screens/profile/CaptionScreen.tsx | 58 |
1 files changed, 41 insertions, 17 deletions
diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx index 2093a1f9..2fe30645 100644 --- a/src/screens/profile/CaptionScreen.tsx +++ b/src/screens/profile/CaptionScreen.tsx @@ -23,7 +23,7 @@ import TaggLoadingIndicator from '../../components/common/TaggLoadingIndicator'; import {TAGG_LIGHT_BLUE_2} from '../../constants'; import {ERROR_UPLOAD, SUCCESS_PIC_UPLOAD} from '../../constants/strings'; import {MainStackParams} from '../../routes'; -import {postMoment} from '../../services'; +import {postMoment, postMomentTags} from '../../services'; import { loadUserMoments, updateProfileCompletionStage, @@ -85,27 +85,51 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => { }; const handleShare = async () => { + const handleFailed = () => { + setLoading(false); + setTimeout(() => { + Alert.alert(ERROR_UPLOAD); + }, 500); + }; + const handleSuccess = () => { + setLoading(false); + navigateToProfile(); + setTimeout(() => { + Alert.alert(SUCCESS_PIC_UPLOAD); + }, 500); + }; setLoading(true); if (!image.filename) { return; } - postMoment(image.filename, image.path, caption, title, userId).then( - (data) => { - setLoading(false); - if (data) { - dispatch(loadUserMoments(userId)); - dispatch(updateProfileCompletionStage(data)); - navigateToProfile(); - setTimeout(() => { - Alert.alert(SUCCESS_PIC_UPLOAD); - }, 500); - } else { - setTimeout(() => { - Alert.alert(ERROR_UPLOAD); - }, 500); - } - }, + const momentResponse = await postMoment( + image.filename, + image.path, + caption, + title, + userId, + ); + if (!momentResponse) { + handleFailed(); + return; + } + const momentTagResponse = await postMomentTags( + momentResponse.moment_id, + taggedUsers.map((u, index) => ({ + x: index * 50 - 150, + y: index * 50 - 150, + user_id: u.id, + })), + ); + if (!momentTagResponse) { + handleFailed(); + return; + } + dispatch(loadUserMoments(userId)); + dispatch( + updateProfileCompletionStage(momentResponse.profile_completion_stage), ); + handleSuccess(); }; return ( |