aboutsummaryrefslogtreecommitdiff
path: root/src/screens/profile/CaptionScreen.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/screens/profile/CaptionScreen.tsx')
-rw-r--r--src/screens/profile/CaptionScreen.tsx14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx
index 53c47a6d..d65a8451 100644
--- a/src/screens/profile/CaptionScreen.tsx
+++ b/src/screens/profile/CaptionScreen.tsx
@@ -9,7 +9,7 @@ import {RouteProp} from '@react-navigation/native';
import {ProfileStackParams} from 'src/routes';
import {StackNavigationProp} from '@react-navigation/stack';
import {CaptionScreenHeader} from '../../components/profile';
-import {MOMENTS_UPLOAD_ENDPOINT} from '../../constants';
+import {MOMENTS_ENDPOINT} from '../../constants';
import {AuthContext} from '../../routes/authentication';
const NO_USER: UserType = {
@@ -34,8 +34,8 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
const {title, image} = route.params;
const {
user: {userId},
+ updateMoments,
} = React.useContext(AuthContext);
- const [user, setUser] = useState<UserType>(NO_USER);
const [caption, setCaption] = React.useState('');
const handleCaptionUpdate = (caption: string) => {
@@ -53,11 +53,6 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
const handleShare = async () => {
try {
- const token = await AsyncStorage.getItem('token');
- if (!token) {
- setUser(NO_USER);
- return;
- }
const request = new FormData();
const uri = image.path;
const name = image.filename;
@@ -69,7 +64,8 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
request.append('moment', title);
request.append('user_id', userId);
request.append('captions', JSON.stringify({image: caption}));
- let response = await fetch(MOMENTS_UPLOAD_ENDPOINT, {
+ const token = await AsyncStorage.getItem('token');
+ let response = await fetch(MOMENTS_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data',
@@ -81,6 +77,7 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
let data = await response.json();
if (statusCode === 200 && checkImageUploadStatus(data)) {
Alert.alert('The picture was uploaded successfully!');
+ updateMoments(true);
navigation.navigate('Profile');
} else {
Alert.alert('An error occured while uploading. Please try again!');
@@ -89,6 +86,7 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
Alert.alert('An error occured during authenticaion. Please login again!');
}
};
+
return (
<SearchBackground>
<View style={styles.contentContainer}>