diff options
Diffstat (limited to 'src/components/profile/Friends.tsx')
-rw-r--r-- | src/components/profile/Friends.tsx | 97 |
1 files changed, 14 insertions, 83 deletions
diff --git a/src/components/profile/Friends.tsx b/src/components/profile/Friends.tsx index a7a06567..f800597b 100644 --- a/src/components/profile/Friends.tsx +++ b/src/components/profile/Friends.tsx @@ -1,98 +1,39 @@ -import React, {useEffect, useState} from 'react'; +import React from 'react'; import {ScrollView, StyleSheet, Text, View} from 'react-native'; -import {checkPermission} from 'react-native-contacts'; import {TouchableOpacity} from 'react-native-gesture-handler'; import {useDispatch, useStore} from 'react-redux'; import {TAGG_LIGHT_BLUE} from '../../constants'; -import {usersFromContactsService} from '../../services'; import {NO_USER} from '../../store/initialStates'; import {RootState} from '../../store/rootReducer'; import {ProfilePreviewType, ScreenType} from '../../types'; -import { - extractContacts, - normalize, - SCREEN_HEIGHT, - SCREEN_WIDTH, -} from '../../utils'; -import {handleAddFriend, handleUnfriend} from '../../utils/friends'; +import {normalize, SCREEN_HEIGHT, SCREEN_WIDTH} from '../../utils'; +import {handleUnfriend} from '../../utils/friends'; import {ProfilePreview} from '../profile'; interface FriendsProps { result: Array<ProfilePreviewType>; screenType: ScreenType; userId: string | undefined; + hideFriendsFeature?: boolean; } -const Friends: React.FC<FriendsProps> = ({result, screenType, userId}) => { +const Friends: React.FC<FriendsProps> = ({ + result, + screenType, + userId, + hideFriendsFeature, +}) => { const state: RootState = useStore().getState(); const dispatch = useDispatch(); const {user: loggedInUser = NO_USER} = state.user; - const [usersFromContacts, setUsersFromContacts] = useState< - ProfilePreviewType[] - >([]); - - useEffect(() => { - const handleFindFriends = () => { - extractContacts().then(async (contacts) => { - const permission = await checkPermission(); - if (permission === 'authorized') { - let response = await usersFromContactsService(contacts); - setUsersFromContacts(response.existing_tagg_users); - } else { - console.log('Authorize access to contacts'); - } - }); - }; - handleFindFriends(); - }, []); - - const UsersFromContacts = () => ( - <> - {usersFromContacts?.splice(0, 2).map((profilePreview) => ( - <View key={profilePreview.id} style={styles.container}> - <View style={styles.friend}> - <ProfilePreview - {...{profilePreview}} - previewType={'Friend'} - screenType={screenType} - /> - </View> - <TouchableOpacity - style={styles.addFriendButton} - onPress={() => { - handleAddFriend(screenType, profilePreview, dispatch, state).then( - (success) => { - if (success) { - let users = usersFromContacts; - setUsersFromContacts( - users.filter( - (user) => user.username !== profilePreview.username, - ), - ); - } - }, - ); - }}> - <Text style={styles.addFriendButtonTitle}>Add Friend</Text> - </TouchableOpacity> - </View> - ))} - </> - ); return ( <> - {loggedInUser.userId === userId && usersFromContacts.length !== 0 && ( - <View style={styles.subheader}> - <View style={styles.addFriendHeaderContainer}> - <Text style={[styles.subheaderText]}>Contacts on Tagg</Text> - </View> - <UsersFromContacts /> - </View> + {!hideFriendsFeature && ( + <Text style={[styles.subheaderText, styles.friendsSubheaderText]}> + Friends + </Text> )} - <Text style={[styles.subheaderText, styles.friendsSubheaderText]}> - Friends - </Text> <ScrollView keyboardShouldPersistTaps={'always'} style={styles.scrollView} @@ -129,7 +70,6 @@ const styles = StyleSheet.create({ alignSelf: 'center', width: SCREEN_WIDTH * 0.85, }, - firstScrollView: {}, scrollViewContent: { alignSelf: 'center', paddingBottom: SCREEN_HEIGHT / 7, @@ -142,7 +82,6 @@ const styles = StyleSheet.create({ marginBottom: '3%', marginTop: '2%', }, - header: {flexDirection: 'row'}, subheader: { alignSelf: 'center', width: SCREEN_WIDTH * 0.85, @@ -154,20 +93,12 @@ const styles = StyleSheet.create({ fontWeight: '600', lineHeight: normalize(14.32), }, - findFriendsButton: {flexDirection: 'row'}, friendsSubheaderText: { alignSelf: 'center', width: SCREEN_WIDTH * 0.85, marginVertical: '1%', marginBottom: '2%', }, - findFriendsSubheaderText: { - marginLeft: '5%', - color: '#08E2E2', - fontSize: normalize(12), - fontWeight: '600', - lineHeight: normalize(14.32), - }, container: { alignSelf: 'center', flexDirection: 'row', |