aboutsummaryrefslogtreecommitdiff
path: root/src/screens/profile/CaptionScreen.tsx
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-05-21 21:23:55 -0400
committerIvan Chen <ivan@tagg.id>2021-05-21 21:23:55 -0400
commit923e1084e18ce5636cf4448096907bc95f1018ff (patch)
tree788ab7982a82a5c94d86e5c23d2c7fd4b2c5921e /src/screens/profile/CaptionScreen.tsx
parent29cfccc7010aee6a5c5f47db4881810fa2b75b9f (diff)
Add api calls
Diffstat (limited to 'src/screens/profile/CaptionScreen.tsx')
-rw-r--r--src/screens/profile/CaptionScreen.tsx58
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 (