import {RouteProp} from '@react-navigation/native'; import {StackNavigationProp} from '@react-navigation/stack'; import React, {Fragment, useState} from 'react'; import { Alert, Image, Keyboard, KeyboardAvoidingView, Platform, StyleSheet, TouchableWithoutFeedback, View, } from 'react-native'; import {Button} from 'react-native-elements'; import {useDispatch, useSelector} from 'react-redux'; import {SearchBackground, TaggBigInput} from '../../components'; import {CaptionScreenHeader} from '../../components/'; 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 { loadUserMoments, updateProfileCompletionStage, } from '../../store/actions'; import {RootState} from '../../store/rootReducer'; import {SCREEN_WIDTH, StatusBarHeight} from '../../utils'; /** * Upload Screen to allow users to upload posts to Tagg */ type CaptionScreenRouteProp = RouteProp; type CaptionScreenNavigationProp = StackNavigationProp< MainStackParams, 'CaptionScreen' >; interface CaptionScreenProps { route: CaptionScreenRouteProp; navigation: CaptionScreenNavigationProp; } const CaptionScreen: React.FC = ({route, navigation}) => { const {title, image, screenType} = route.params; const { user: {userId}, } = useSelector((state: RootState) => state.user); const dispatch = useDispatch(); const [caption, setCaption] = useState(''); const [loading, setLoading] = useState(false); const handleCaptionUpdate = (newCaption: string) => { setCaption(newCaption); }; const navigateToProfile = () => { //Since the logged In User is navigating to own profile, useXId is not required navigation.navigate('Profile', { screenType, userXId: undefined, }); }; const handleShare = async () => { 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); } }, ); }; return ( {loading ? : }