From 1499c0126d1a7a2377b0267b761479100c636ee9 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Tue, 30 Jun 2020 00:41:09 +0300
Subject: feat!: create useNavigate hook

---
 src/pages/ProfilePage/ProfilePage.tsx | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

(limited to 'src/pages/ProfilePage/ProfilePage.tsx')

diff --git a/src/pages/ProfilePage/ProfilePage.tsx b/src/pages/ProfilePage/ProfilePage.tsx
index ad2da46..808d43a 100644
--- a/src/pages/ProfilePage/ProfilePage.tsx
+++ b/src/pages/ProfilePage/ProfilePage.tsx
@@ -4,16 +4,18 @@ import { User, Poll } from 'which-types';
 import ProfileInfo from './ProfileInfo';
 import Feed from '../../components/Feed/Feed';
 import { get } from '../../requests';
+import { useAuth } from '../../hooks/useAuth'; 
+import { useNavigate } from '../../hooks/useNavigate'; 
 
-interface PropTypes {
-  navigate: (prefix: string, id: string) => void;
-  id: string;
-}
 
-const ProfilePage: React.FC<PropTypes> = ({ id, navigate }) => {
+const ProfilePage: React.FC = () => {
   const [userInfo, setUserInfo] = useState<User>();
   const [polls, setPolls] = useState<Poll[]>([]);
   const [totalVotes, setTotalVotes] = useState<number>(0);
+  const { page } = useNavigate();
+  const { user } = useAuth();
+
+  const id = page?.id || user?._id;
 
   useEffect(() => {
     get(`/users/${id}`).then(response => {
@@ -41,7 +43,7 @@ const ProfilePage: React.FC<PropTypes> = ({ id, navigate }) => {
         savedPolls={polls.length}
         totalVotes={totalVotes}
       />
-      <Feed polls={[...polls]} navigate={navigate} />
+      <Feed polls={[...polls]} />
     </>
   );
 };
-- 
cgit v1.2.3

