import {RouteProp} from '@react-navigation/native'; import {StackNavigationProp} from '@react-navigation/stack'; import React, {Fragment, useEffect, useState} from 'react'; import { Alert, Image, Keyboard, KeyboardAvoidingView, Platform, StyleSheet, Text, TouchableOpacity, TouchableWithoutFeedback, View, } from 'react-native'; import {MentionInput} from 'react-native-controlled-mentions'; import {Button, normalize} from 'react-native-elements'; import {useDispatch, useSelector} from 'react-redux'; import FrontArrow from '../../assets/icons/front-arrow.svg'; import {SearchBackground} 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, postMomentTags} from '../../services'; import { loadUserMoments, updateProfileCompletionStage, } from '../../store/actions'; import {RootState} from '../../store/rootReducer'; import {ProfilePreviewType} from '../../types'; import {SCREEN_WIDTH, StatusBarHeight} from '../../utils'; import {mentionPartTypes} from '../../utils/comments'; /** * 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, selectedUsers} = route.params; const { user: {userId}, } = useSelector((state: RootState) => state.user); const dispatch = useDispatch(); const [caption, setCaption] = useState(''); const [loading, setLoading] = useState(false); const [taggedUsers, setTaggedUsers] = useState([]); const [taggedList, setTaggedList] = useState(''); useEffect(() => { setTaggedUsers(selectedUsers ? selectedUsers : []); }, [route.params]); useEffect(() => { const getTaggedUsersListString = () => { let listString = ''; for (let i = 0; i < taggedUsers.length; i++) { if (listString.length < 21) { listString = listString.concat(`@${taggedUsers[i].username} `); } else { break; } } setTaggedList(listString); }; getTaggedUsersListString(); }, [taggedUsers]); 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 () => { const handleFailed = () => { setLoading(false); setTimeout(() => { Alert.alert(ERROR_UPLOAD); }, 500); }; const handleSuccess = () => { setLoading(false); navigateToProfile(); setTimeout(() => { Alert.alert(SUCCESS_PIC_UPLOAD); }, 500); }; setLoading(true); if (!image.filename) { return; } const momentResponse = await postMoment( image.filename, image.path, caption, title, userId, ); if (!momentResponse) { handleFailed(); return; } const momentTagResponse = await postMomentTags( momentResponse.moment_id, taggedUsers.map((u, index) => ({ x: index * 50 - 150, y: index * 50 - 150, user_id: u.id, })), ); if (!momentTagResponse) { handleFailed(); return; } dispatch(loadUserMoments(userId)); dispatch( updateProfileCompletionStage(momentResponse.profile_completion_stage), ); handleSuccess(); }; return ( {loading ? : }