1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
import React from 'react';
import {LayoutChangeEvent, Linking, StyleSheet, Text, View} from 'react-native';
import {normalize} from 'react-native-elements';
import {useDispatch, useSelector, useStore} from 'react-redux';
import {
TAGG_DARK_BLUE,
TAGG_LIGHT_BLUE,
TOGGLE_BUTTON_TYPE,
} from '../../constants';
import {
acceptFriendRequest,
declineFriendRequest,
updateUserXFriends,
updateUserXProfileAllScreens,
} from '../../store/actions';
import {NO_PROFILE, NO_USER} from '../../store/initialStates';
import {RootState} from '../../store/rootReducer';
import {ScreenType} from '../../types';
import {getUserAsProfilePreviewType, SCREEN_WIDTH} from '../../utils';
import {FriendsButton} from '../common';
import ToggleButton from './ToggleButton';
interface ProfileBodyProps {
onLayout: (event: LayoutChangeEvent) => void;
isBlocked: boolean;
handleBlockUnblock: () => void;
userXId: string | undefined;
screenType: ScreenType;
}
const ProfileBody: React.FC<ProfileBodyProps> = ({
onLayout,
isBlocked,
handleBlockUnblock,
userXId,
screenType,
}) => {
const {profile = NO_PROFILE, user} = userXId
? useSelector((state: RootState) => state.userX[screenType][userXId])
: useSelector((state: RootState) => state.user);
const {user: loggedInUser = NO_USER} = 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 (
<View onLayout={onLayout} style={styles.container}>
<Text style={styles.username}>{`@${username}`}</Text>
{biography.length > 0 && (
<Text style={styles.biography}>{`${biography}`}</Text>
)}
{website.length > 0 && (
<Text
style={styles.website}
onPress={() => {
Linking.openURL(
website.startsWith('http') ? website : 'http://' + website,
);
}}>{`${website}`}</Text>
)}
{userXId && isBlocked && (
<View style={styles.toggleButtonContainer}>
<ToggleButton
toggleState={isBlocked}
handleToggle={handleBlockUnblock}
buttonType={TOGGLE_BUTTON_TYPE.BLOCK_UNBLOCK}
/>
</View>
)}
{userXId && !isBlocked && (
<View style={styles.buttonsContainer}>
<FriendsButton
userXId={userXId}
screenType={screenType}
friendship_requester_id={friendship_requester_id}
onAcceptRequest={handleAcceptRequest}
onRejectRequest={handleDeclineFriendRequest}
/>
</View>
)}
</View>
);
};
const styles = StyleSheet.create({
toggleButtonContainer: {
flexDirection: 'row',
flex: 1,
paddingTop: '3.5%',
paddingBottom: '2%',
},
buttonsContainer: {
flex: 1,
paddingTop: '3.5%',
paddingBottom: '2%',
},
container: {
paddingVertical: '1%',
paddingHorizontal: 18,
backgroundColor: 'white',
},
username: {
fontWeight: '600',
fontSize: normalize(12),
marginBottom: '1%',
},
biography: {
fontSize: normalize(12),
marginBottom: '1.5%',
},
website: {
fontSize: normalize(12),
color: TAGG_DARK_BLUE,
marginBottom: '1%',
},
});
export default ProfileBody;
|