aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/components/common/AcceptDeclineButtons.tsx22
-rw-r--r--src/components/notifications/Notification.tsx4
-rw-r--r--src/components/profile/Content.tsx25
-rw-r--r--src/components/profile/ProfileBody.tsx4
-rw-r--r--src/components/profile/ProfilePreview.tsx27
-rw-r--r--src/store/actions/userX.ts15
-rw-r--r--src/store/reducers/userXReducer.ts2
-rw-r--r--src/utils/common.ts2
-rw-r--r--src/utils/users.ts16
9 files changed, 44 insertions, 73 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',
);
diff --git a/src/store/actions/userX.ts b/src/store/actions/userX.ts
index 6772837b..39d3f918 100644
--- a/src/store/actions/userX.ts
+++ b/src/store/actions/userX.ts
@@ -131,6 +131,7 @@ export const resetScreenType = (
export const updateUserXProfileAllScreens = (
userId: string,
+ state: RootState,
): ThunkAction<Promise<void>, RootState, unknown, Action<string>> => async (
dispatch,
) => {
@@ -142,13 +143,15 @@ export const updateUserXProfileAllScreens = (
];
const token = await getTokenOrLogout(dispatch);
screens.forEach((screenType) => {
- loadProfileInfo(token, userId).then((data) => {
- console.log('DATA FETCHED: ', data);
- dispatch({
- type: userXProfileFetched.type,
- payload: {screenType, userId, data},
+ if (userXInStore(state, screenType, userId)) {
+ loadProfileInfo(token, userId).then((data) => {
+ console.log('DATA FETCHED: ', data);
+ dispatch({
+ type: userXProfileFetched.type,
+ payload: {screenType, userId, data},
+ });
});
- });
+ }
});
} catch (error) {
console.log(error);
diff --git a/src/store/reducers/userXReducer.ts b/src/store/reducers/userXReducer.ts
index 42de806d..9f90d58d 100644
--- a/src/store/reducers/userXReducer.ts
+++ b/src/store/reducers/userXReducer.ts
@@ -64,8 +64,6 @@ const userXSlice = createSlice({
state[<ScreenType>action.payload.screenType][
action.payload.userId
].profile.friendship_status = action.payload.data;
-
- console.log('Inside state management friends', action.payload);
},
resetScreen: (state, action) => {
diff --git a/src/utils/common.ts b/src/utils/common.ts
index dbe8f270..6314cc13 100644
--- a/src/utils/common.ts
+++ b/src/utils/common.ts
@@ -1,5 +1,5 @@
import moment from 'moment';
-import {Linking} from 'react-native';
+import {AsyncStorage, Linking} from 'react-native';
import {BROWSABLE_SOCIAL_URLS, TOGGLE_BUTTON_TYPE} from '../constants';
export const getToggleButtonText: (
diff --git a/src/utils/users.ts b/src/utils/users.ts
index d4aaebe3..ca917ae4 100644
--- a/src/utils/users.ts
+++ b/src/utils/users.ts
@@ -1,6 +1,6 @@
import AsyncStorage from '@react-native-community/async-storage';
import {INTEGRATED_SOCIAL_LIST} from '../constants';
-import {loadSocialPosts} from '../services';
+import {isUserBlocked, loadSocialPosts} from '../services';
import {
loadAllSocials,
loadBlockedList,
@@ -9,6 +9,7 @@ import {
loadUserData,
loadUserMoments,
loadUserNotifications,
+ logout,
} from '../store/actions';
import {NO_SOCIAL_ACCOUNTS} from '../store/initialStates';
import {userLoggedIn} from '../store/reducers';
@@ -145,3 +146,16 @@ export const getUserAsProfilePreviewType = (
last_name: fullName[1],
};
};
+
+export const checkIfUserIsBlocked = async (
+ userId: string,
+ dispatch: Function,
+ loggedInUser: UserType,
+) => {
+ const token = await AsyncStorage.getItem('token');
+ if (!token) {
+ dispatch(logout());
+ return false;
+ }
+ return await isUserBlocked(userId, loggedInUser.userId, token);
+};