diff options
author | Shravya Ramesh <37447613+shravyaramesh@users.noreply.github.com> | 2020-10-19 12:42:15 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-19 15:42:15 -0400 |
commit | 1b7fef188ec2aee0706fc1204432315db3d4fec6 (patch) | |
tree | 0f07d060f9f0f7343442f968d1a4be9b1ceff03f /src/screens/profile/CaptionScreen.tsx | |
parent | f5853b77ef9506df056029282c475e5628fb6ab0 (diff) |
Tma235/231 Individual view and horizontal view (#59)
* Implemented modal stack navigation for moment view, created a rough UI for individual moment view [incl: title, image(not displayed)]
* bare bones beginnning
* Created individual moment screen, moment tile for horizontal view
* Alert
* Fix initial route
Co-authored-by: Ashm Walia <ashmwalia@outlook.com>
Co-authored-by: Ashm Walia <40498934+ashmgarv@users.noreply.github.com>
Diffstat (limited to 'src/screens/profile/CaptionScreen.tsx')
-rw-r--r-- | src/screens/profile/CaptionScreen.tsx | 14 |
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}> |