diff --git a/client/src/components/FollowedBy.tsx b/client/src/components/FollowedBy.tsx
index 303f131..e4dd475 100644
--- a/client/src/components/FollowedBy.tsx
+++ b/client/src/components/FollowedBy.tsx
@@ -152,7 +152,10 @@ const FollowedBy = (): JSX.Element => {
}
onClick={async () => {
if (userInformation.type !== "bot") {
- await routeToProfilePage({ userID: userInformation.userID });
+ await routeToProfilePage({
+ userID: userInformation.userID,
+ from: "followedByComp",
+ });
} else {
toastError("Sorry!!, can't be able to open bot Profile");
}
@@ -164,7 +167,10 @@ const FollowedBy = (): JSX.Element => {
className="MainPage_Followed_User_Name"
onClick={async () => {
if (userInformation.type !== "bot") {
- await routeToProfilePage({ userID: userInformation.userID });
+ await routeToProfilePage({
+ userID: userInformation.userID,
+ from: "followedByComp",
+ });
} else {
toastError("Sorry!!, can't be able to open bot Profile");
}
@@ -176,7 +182,10 @@ const FollowedBy = (): JSX.Element => {
className="MainPage_Followed_User_Follower_Name"
onClick={async () => {
if (userInformation.type !== "bot") {
- await routeToProfilePage({ userID: userInformation.userID });
+ await routeToProfilePage({
+ userID: userInformation.userID,
+ from: "followedByComp",
+ });
} else {
toastError("Sorry!!, can't be able to open bot Profile");
}
diff --git a/client/src/components/ProfileFriends.tsx b/client/src/components/ProfileFriends.tsx
index afd6700..583c6b4 100644
--- a/client/src/components/ProfileFriends.tsx
+++ b/client/src/components/ProfileFriends.tsx
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import User_Profile_Icon from "../assets/svg/User_profile_Icon.svg";
import "../styles/components/profileFriends.css";
-import { useHistory, useLocation } from "react-router-dom";
+import { useLocation } from "react-router-dom";
import { toastError } from "../services/toast";
import UserApi from "../services/api/global/user";
import { Helmet } from "react-helmet";
@@ -15,17 +15,16 @@ import { Helmet } from "react-helmet";
// profilePageDataAction,
// setRootUserProfileDataState,
// } from "../services/redux-actions";
-import GlobalApi from "../services/api/global";
import { AppState, actionCreators } from "../services/redux";
import { bindActionCreators } from "redux";
import UserDocument from "../interface/userDocument";
import { AxiosError } from "axios";
-import { ProfilePageDataState } from "src/services/redux/pages/profile/profilePageData/types";
+import useRouteToProfilePage from "../hooks/useRouteToProfilePage";
const ProfileFriends = (): JSX.Element => {
const dispatch = useDispatch();
+ const routeToProfilePage = useRouteToProfilePage();
const location = useLocation();
- const history = useHistory();
const [userDetails, setUserDetails] = useState<{
fetchedData: boolean;
user: UserDocument[];
@@ -43,10 +42,6 @@ const ProfileFriends = (): JSX.Element => {
setProfilePageFriends,
setProfilePageFollowers,
setProfilePageFollowings,
- startProgressBar,
- stopProgressBar,
- profilePageDataAction,
- setRootUserProfileDataState,
} = bindActionCreators(actionCreators, dispatch);
const loadingContainerSpinnerStyle = {
@@ -176,45 +171,10 @@ const ProfileFriends = (): JSX.Element => {
key={index}
style={{ textDecoration: "none", color: "black" }}
onClick={async () => {
- try {
- startProgressBar();
- const res = await GlobalApi.getFriendData(
- userDetail.userID
- );
- const userData = await res.data;
- if (res.status === 200 && userData.success) {
- // success
- const userObj: ProfilePageDataState = {
- ...userData.searchedUser,
- isRootUserFollowed: userData.isRootUserFollowed,
- throughRouting: true,
- };
- profilePageDataAction(userObj);
- if (userDetail.userID === userProfileDetailStore.userID) {
- setRootUserProfileDataState({
- fetchedRootUserProfileData: true,
- getRootUserProfileData: false,
- });
- }
- history.push(`/u/profile/${userDetail.userID}/posts`);
- } else {
- // error
- toastError(userData.msg);
- }
- stopProgressBar();
- } catch (error) {
- const err = error as AxiosError;
- if (err.response) {
- if (err.response.data.success === false) {
- toastError(err.response.data.msg);
- }
- } else {
- toastError(
- "Some Problem Occur, Please Try again later!!!"
- );
- }
- stopProgressBar();
- }
+ routeToProfilePage({
+ userID: userDetail.userID,
+ from: "profileFriendsComp",
+ });
}}
>
{
const dispatch = useDispatch();
- const history = useHistory();
+ const routeToProfilePage = useRouteToProfilePage();
const userProfileDetailStore = useSelector(
(state: AppState) => state.setUserProfileDetailReducer
);
const rootUserFriends = useSelector(
(state: AppState) => state.rootUserFriends
);
- const {
- startProgressBar,
- stopProgressBar,
- setRootUserFriends,
- profilePageDataAction,
- } = bindActionCreators(actionCreators, dispatch);
+ const { setRootUserFriends } = bindActionCreators(actionCreators, dispatch);
const MainPageFriend = (props) => {
return (
@@ -41,37 +34,8 @@ const Friends = () => {