aboutsummaryrefslogtreecommitdiff
path: root/src/screens/profile/CaptionScreen.tsx
diff options
context:
space:
mode:
authorAshm Walia <40498934+ashmgarv@users.noreply.github.com>2020-10-14 12:55:36 -0700
committerGitHub <noreply@github.com>2020-10-14 15:55:36 -0400
commit79d237f616c37940f5d476eb1dca6b5d05cf148a (patch)
tree417386f5e3797e0cb3c51e1fd668ed4c20f4b7c0 /src/screens/profile/CaptionScreen.tsx
parent22142e2f8aa7d5eed8de1e520fd5ce825d2c63ca (diff)
[TMA-232] (Small change) Make call to the correct API on backend and a nitpick (#55)
* Make call to a the correct API on backend and a nitpick * Added a feedback (Alert) after successful image upload * Iterate through the returned data to see if the image was actually uploaded successfully
Diffstat (limited to 'src/screens/profile/CaptionScreen.tsx')
-rw-r--r--src/screens/profile/CaptionScreen.tsx15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx
index 3eb6c47b..e3040509 100644
--- a/src/screens/profile/CaptionScreen.tsx
+++ b/src/screens/profile/CaptionScreen.tsx
@@ -42,6 +42,15 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
setCaption(caption);
};
+ const checkImageUploadStatus = (statusMap : object) => {
+ for(let [key, value] of Object.entries(statusMap)){
+ if (value != "Success"){
+ return false;
+ }
+ }
+ return true;
+ }
+
const handleShare = async () => {
try {
const token = await AsyncStorage.getItem('token');
@@ -59,7 +68,7 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
});
request.append('moment', title);
request.append('user_id', userId);
- request.append('caption', caption);
+ request.append('captions', JSON.stringify({'image':caption}));
let response = await fetch(MOMENTS_UPLOAD_ENDPOINT, {
method: 'POST',
headers: {
@@ -69,7 +78,9 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
body: request,
});
let statusCode = response.status;
- if (statusCode === 200) {
+ let data = await response.json();
+ if (statusCode === 200 && checkImageUploadStatus(data)) {
+ Alert.alert('The picture was uploaded successfully!');
navigation.navigate('Profile');
} else {
Alert.alert('An error occured while uploading. Please try again!');