aboutsummaryrefslogtreecommitdiff
path: root/src/screens/profile/CaptionScreen.tsx
diff options
context:
space:
mode:
authorAshm Walia <40498934+ashmgarv@users.noreply.github.com>2021-01-12 15:38:21 -0800
committerGitHub <noreply@github.com>2021-01-12 18:38:21 -0500
commitd495bff07b50c47e842dc2c139922d56c87f5c9b (patch)
treec6f592fa72a6158981fef2feba1b3dca5ff6cc2a /src/screens/profile/CaptionScreen.tsx
parentc758389ad2ebe98196d4618ec08dbf2b24d95bfa (diff)
[TMA 491 Frontend] Revamp onboarding (#173)
* First commit, arrow excluded * Done from my side * Some small nitpicks * exclude tsconfig * Show profile screen after onboarding * Update string * Small fix * small cosmetic
Diffstat (limited to 'src/screens/profile/CaptionScreen.tsx')
-rw-r--r--src/screens/profile/CaptionScreen.tsx64
1 files changed, 18 insertions, 46 deletions
diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx
index e9eed668..5537d6bf 100644
--- a/src/screens/profile/CaptionScreen.tsx
+++ b/src/screens/profile/CaptionScreen.tsx
@@ -14,20 +14,24 @@ import {SearchBackground, TaggBigInput} from '../../components';
import {SCREEN_WIDTH, StatusBarHeight} from '../../utils';
import AsyncStorage from '@react-native-community/async-storage';
import {RouteProp} from '@react-navigation/native';
-import {ProfileStackParams} from 'src/routes';
+import {MainStackParams} from 'src/routes';
import {StackNavigationProp} from '@react-navigation/stack';
import {CaptionScreenHeader} from '../../components/';
import {MOMENTS_ENDPOINT} from '../../constants';
import {useDispatch, useSelector} from 'react-redux';
-import {loadUserMoments} from '../../store/actions';
+import {
+ loadUserMoments,
+ updateProfileCompletionStage,
+} from '../../store/actions';
import {RootState} from '../../store/rootReducer';
+import {postMoment} from '../../services';
/**
* Upload Screen to allow users to upload posts to Tagg
*/
-type CaptionScreenRouteProp = RouteProp<ProfileStackParams, 'CaptionScreen'>;
+type CaptionScreenRouteProp = RouteProp<MainStackParams, 'CaptionScreen'>;
type CaptionScreenNavigationProp = StackNavigationProp<
- ProfileStackParams,
+ MainStackParams,
'CaptionScreen'
>;
interface CaptionScreenProps {
@@ -47,15 +51,6 @@ 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 navigateToProfile = () => {
//Since the logged In User is navigating to own profile, useXId is not required
navigation.navigate('Profile', {
@@ -66,43 +61,20 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => {
const handleShare = async () => {
try {
- const request = new FormData();
- const uri = image.path;
- var fileName = image.filename;
-
- //Manipulating filename to end with .jpg instead of .heic
- if (fileName.endsWith('.heic') || fileName.endsWith('.HEIC')) {
- fileName = fileName.split('.')[0] + '.jpg';
- }
- request.append('image', {
- uri: uri,
- name: fileName,
- type: 'image/jpg',
- });
- request.append('moment', title);
- request.append('user_id', userId);
- request.append('captions', JSON.stringify({image: caption}));
-
- const token = await AsyncStorage.getItem('token');
- let response = await fetch(MOMENTS_ENDPOINT, {
- method: 'POST',
- headers: {
- 'Content-Type': 'multipart/form-data',
- Authorization: 'Token ' + token,
- },
- body: request,
- });
- let statusCode = response.status;
- let data = await response.json();
- if (statusCode === 200 && checkImageUploadStatus(data)) {
- Alert.alert('The picture was uploaded successfully!');
+ const data = await postMoment(
+ image.filename,
+ image.path,
+ caption,
+ title,
+ userId,
+ );
+ if (data) {
dispatch(loadUserMoments(userId));
+ dispatch(updateProfileCompletionStage(data));
navigateToProfile();
- } else {
- Alert.alert('An error occured while uploading. Please try again!');
}
} catch (err) {
- Alert.alert('An error occured during authenticaion. Please login again!');
+ console.log(err);
}
};