diff options
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/common/AcceptDeclineButtons.tsx | 22 | ||||
-rw-r--r-- | src/components/notifications/Notification.tsx | 4 | ||||
-rw-r--r-- | src/components/profile/Content.tsx | 25 | ||||
-rw-r--r-- | src/components/profile/ProfileBody.tsx | 4 | ||||
-rw-r--r-- | src/components/profile/ProfilePreview.tsx | 27 |
5 files changed, 19 insertions, 63 deletions
diff --git a/src/components/common/AcceptDeclineButtons.tsx b/src/components/common/AcceptDeclineButtons.tsx index 164ce6e7..7d01a398 100644 --- a/src/components/common/AcceptDeclineButtons.tsx +++ b/src/components/common/AcceptDeclineButtons.tsx @@ -1,22 +1,6 @@ import React from 'react'; -import { - StyleProp, - StyleSheet, - Text, - View, - ViewProps, - ViewStyle, -} from 'react-native'; -import {Button} from 'react-native-elements'; -import {useDispatch, useStore} from 'react-redux'; -import { - declineFriendRequest, - loadUserNotifications, - updateUserXFriends, -} from '../../store/actions'; +import {StyleProp, StyleSheet, Text, View, ViewStyle} from 'react-native'; import {TAGG_TEXT_LIGHT_BLUE} from '../../constants'; -import {acceptFriendRequest} from '../../store/actions'; -import {RootState} from '../../store/rootReducer'; import {ProfilePreviewType} from '../../types'; import {SCREEN_WIDTH} from '../../utils'; import {TouchableOpacity} from 'react-native-gesture-handler'; @@ -62,8 +46,8 @@ const styles = StyleSheet.create({ genericButtonStyle: { justifyContent: 'center', alignItems: 'center', - width: SCREEN_WIDTH * 0.2, - height: SCREEN_WIDTH * 0.07, + width: SCREEN_WIDTH * 0.15, + height: SCREEN_WIDTH * 0.06, borderRadius: 5, padding: 0, marginTop: 10, diff --git a/src/components/notifications/Notification.tsx b/src/components/notifications/Notification.tsx index 42b10ea3..efbda46f 100644 --- a/src/components/notifications/Notification.tsx +++ b/src/components/notifications/Notification.tsx @@ -9,14 +9,12 @@ import { loadUserNotifications, updateUserXFriends, } from '../../store/actions'; -import {TAGG_TEXT_LIGHT_BLUE} from '../../constants'; -import {loadAvatar, unfriendUser} from '../../services'; +import {loadAvatar} from '../../services'; import {acceptFriendRequest} from '../../store/actions'; import {RootState} from '../../store/rootReducer'; import {NotificationType, ProfilePreviewType, ScreenType} from '../../types'; import { fetchUserX, - getTokenOrLogout, SCREEN_HEIGHT, SCREEN_WIDTH, userXInStore, diff --git a/src/components/profile/Content.tsx b/src/components/profile/Content.tsx index f7b4b71c..cc9849e6 100644 --- a/src/components/profile/Content.tsx +++ b/src/components/profile/Content.tsx @@ -42,6 +42,7 @@ import { updateUserXFriends, updateMomentCategories, deleteUserMomentsForCategory, + updateUserXProfileAllScreens, } from '../../store/actions'; import { NO_USER, @@ -214,29 +215,6 @@ const Content: React.FC<ContentProps> = ({y, userXId, screenType}) => { } }, [blockedUsers, user]); - // /** - // * The object returned by this method is added to the list of blocked / friended users by the reducer. - // * Which helps us prevent an extra api call to the backend just to fetch a user. - // */ - // const getUserAsProfilePreviewType = ( - // passedInUser: UserType, - // passedInProfile: ProfileType, - // ): ProfilePreviewType => { - // const fullName = passedInProfile.name.split(' '); - // return { - // id: passedInUser.userId, - // username: passedInUser.username, - // first_name: fullName[0], - // last_name: fullName[1], - // }; - // }; - - /** - * Handles a click on the friend / unfriend button. - * friendUnfriendUser takes care of updating the friends list for loggedInUser - * updateUserXFriends updates friends list for the new friend. - */ - // Handles click on friend/requested/unfriend button /* * When user logged in clicks on the friend button: @@ -259,6 +237,7 @@ const Content: React.FC<ContentProps> = ({y, userXId, screenType}) => { ), ); await dispatch(updateUserXFriends(user.userId, state)); + dispatch(updateUserXProfileAllScreens(user.userId, state)); }; /** diff --git a/src/components/profile/ProfileBody.tsx b/src/components/profile/ProfileBody.tsx index edda5d43..4076e473 100644 --- a/src/components/profile/ProfileBody.tsx +++ b/src/components/profile/ProfileBody.tsx @@ -62,7 +62,7 @@ const ProfileBody: React.FC<ProfileBodyProps> = ({ acceptFriendRequest({id, username, first_name, last_name}), ); await dispatch(updateUserXFriends(id, state)); - dispatch(updateUserXProfileAllScreens(id)); + dispatch(updateUserXProfileAllScreens(id, state)); } catch (err) { console.log(err); } @@ -70,7 +70,7 @@ const ProfileBody: React.FC<ProfileBodyProps> = ({ const handleDeclineFriendRequest = async () => { await dispatch(declineFriendRequest(id)); - dispatch(updateUserXProfileAllScreens(id)); + dispatch(updateUserXProfileAllScreens(id, state)); }; return ( diff --git a/src/components/profile/ProfilePreview.tsx b/src/components/profile/ProfilePreview.tsx index 6f008540..0d8d9852 100644 --- a/src/components/profile/ProfilePreview.tsx +++ b/src/components/profile/ProfilePreview.tsx @@ -18,7 +18,7 @@ import {isUserBlocked, loadAvatar} from '../../services'; import {useSelector, useDispatch, useStore} from 'react-redux'; import {RootState} from '../../store/rootreducer'; import {logout} from '../../store/actions'; -import {fetchUserX, userXInStore} from '../../utils'; +import {checkIfUserIsBlocked, fetchUserX, userXInStore} from '../../utils'; import {SearchResultsBackground} from '../search'; import NavigationBar from 'src/routes/tabs'; @@ -72,15 +72,6 @@ const ProfilePreview: React.FC<ProfilePreviewProps> = ({ * needed to make space. */ - const checkIfUserIsBlocked = async (userId: string) => { - const token = await AsyncStorage.getItem('token'); - if (!token) { - dispatch(logout()); - return false; - } - return await isUserBlocked(userId, loggedInUser.userId, token); - }; - const state: RootState = useStore().getState(); const addToRecentlyStoredAndNavigateToProfile = async () => { @@ -92,13 +83,17 @@ const ProfilePreview: React.FC<ProfilePreviewProps> = ({ }; try { + //If the logged in user is blocked by the user being viewed, do not proceed. + const isUserBlocked = await checkIfUserIsBlocked( + user.id, + dispatch, + loggedInUser, + ); + if (isUserBlocked) { + Alert.alert('You cannot view this profile'); + return; + } if (previewType !== 'Comment') { - //If the logged in user is blocked by the user being viewed, do not proceed. - const isUserBlocked = await checkIfUserIsBlocked(user.id); - if (isUserBlocked) { - Alert.alert('You cannot view this profile'); - return; - } const jsonValue = await AsyncStorage.getItem( '@recently_searched_users', ); |