From 61a424debfbfa98570e070fbf25d03aa9c56d679 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sun, 14 Jun 2020 20:39:16 +0300
Subject: refactor: structurize pages

---
 src/pages/ProfilePage/ProfilePage.tsx | 37 +++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 15 deletions(-)

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

diff --git a/src/pages/ProfilePage/ProfilePage.tsx b/src/pages/ProfilePage/ProfilePage.tsx
index ee95769..023f37c 100644
--- a/src/pages/ProfilePage/ProfilePage.tsx
+++ b/src/pages/ProfilePage/ProfilePage.tsx
@@ -1,25 +1,32 @@
-import React from 'react';
-import { User } from '../../types';
-import SignInForm from './SignInForm';
+import React, { useState } from 'react';
+import { User, Poll } from '../../types';
 import ProfileInfo from './ProfileInfo';
 import Feed from '../../components/Feed/Feed';
+import { get } from '../../requests';
 
 interface PropTypes {
-  setUser: (newUser: User | undefined) => void;
-  user: User | undefined;
+  logOut: () => void;
+  id: string;
 }
 
-const ProfilePage: React.FC<PropTypes> = ({ setUser, user }) => {
+const ProfilePage: React.FC<PropTypes> = ({ logOut, id }) => {
+  const [userInfo, setUserInfo] = useState<User>();
+  const [polls, setPolls] = useState<Poll[]>([]);
+
+  get(`/users/${id}`).then(response => {
+    setUserInfo(response.data);
+  });
+
+  get(`/profiles/${id}`).then(response => {
+    setPolls(response.data);
+  });
+
   return (
-    user
-      ? (
-        <>
-          <ProfileInfo id={user?._id} setUser={setUser} />
-          <Feed page="Feed" />
-        </>
-      )
-      : <SignInForm setUser={setUser} />
-  );
+    <>
+      <ProfileInfo user={userInfo} logOut={logOut} />
+      <Feed polls={polls} />
+    </>
+  )
 };
 
 export default ProfilePage;
-- 
cgit v1.2.3

