import React from 'react'; import {StyleSheet, View, Text, LayoutChangeEvent, Linking} from 'react-native'; import {Button, normalize} from 'react-native-elements'; import { TAGG_DARK_BLUE, TAGG_LIGHT_BLUE, TOGGLE_BUTTON_TYPE, } from '../../constants'; import ToggleButton from './ToggleButton'; import {RootState} from '../../store/rootReducer'; import {useDispatch, useSelector, useStore} from 'react-redux'; import {FriendshipStatusType, ScreenType} from '../../types'; import {NO_PROFILE} from '../../store/initialStates'; import {getUserAsProfilePreviewType, SCREEN_WIDTH} from '../../utils'; import {AcceptDeclineButtons} from '../common'; import { acceptFriendRequest, declineFriendRequest, loadUserNotifications, updateUserXFriends, updateUserXProfileAllScreens, } from '../../store/actions'; interface ProfileBodyProps { onLayout: (event: LayoutChangeEvent) => void; isBlocked: boolean; handleFriendUnfriend: () => void; handleBlockUnblock: () => void; userXId: string | undefined; screenType: ScreenType; } const ProfileBody: React.FC = ({ onLayout, isBlocked, handleFriendUnfriend, handleBlockUnblock, userXId, screenType, }) => { const {profile = NO_PROFILE, user} = userXId ? useSelector((state: RootState) => state.userX[screenType][userXId]) : useSelector((state: RootState) => state.user); const { biography, website, friendship_status, friendship_requester_id, } = profile; const {id, username, first_name, last_name} = getUserAsProfilePreviewType( user, profile, ); const state: RootState = useStore().getState(); const dispatch = useDispatch(); const handleAcceptRequest = async () => { await dispatch(acceptFriendRequest({id, username, first_name, last_name})); await dispatch(updateUserXFriends(id, state)); dispatch(updateUserXProfileAllScreens(id, state)); }; const handleDeclineFriendRequest = async () => { await dispatch(declineFriendRequest(id)); dispatch(updateUserXProfileAllScreens(id, state)); }; return ( {`@${username}`} {biography.length > 0 && ( {`${biography}`} )} {website.length > 0 && ( { Linking.openURL( website.startsWith('http') ? website : 'http://' + website, ); }}>{`${website}`} )} {userXId && isBlocked && ( )} {userXId && !isBlocked && ( {friendship_status === 'no_record' && (