From 3969face39ecc933b1cb9c7625be921d148552cb Mon Sep 17 00:00:00 2001
From: ilyayudovin <ilyayudovin123@gmail.com>
Date: Sun, 14 Jun 2020 01:31:05 +0300
Subject: feat: add sing in form

---
 src/index.tsx | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

(limited to 'src/index.tsx')

diff --git a/src/index.tsx b/src/index.tsx
index adf44a5..98be8a7 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -13,7 +13,8 @@ import Header from './Header/Header';
 import Feed from './Feed/Feed';
 import ProfileInfo from './ProfileInfo/ProfileInfo';
 
-import { get } from './requests';
+import SignInForm from './Form/SignInForm';
+import { User } from './types';
 
 const theme = createMuiTheme({
   palette: {
@@ -33,20 +34,17 @@ const useStyles = makeStyles({
 
 const App: React.FC = () => {
   const [page, setPage] = useState('feed');
-  const [id, setId] = useState<string>('');
+  const [user, setUser] = React.useState<User | undefined>();
   const classes = useStyles();
 
-  get('/users').then(response => {
-    setId(response.data[0]._id);
-  });
-
   return (
     <ThemeProvider theme={theme}>
       <CssBaseline />
       <Header setPage={setPage} />
       <div className={classes.root}>
         {
-          page === 'profile' && <ProfileInfo id={id} />
+          // eslint-disable-next-line
+          page === 'profile' && (!user ? <SignInForm setUser={setUser} /> : <ProfileInfo id={user?._id || ''} setUser={setUser} />)
         }
         <Feed page={page} />
       </div>
-- 
cgit v1.2.3


From 4a8924b3d214b8f5b78f8e31f2a16a0d2d461b1a Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sun, 14 Jun 2020 03:05:04 +0300
Subject: feat: do not render feed under login form

---
 src/index.tsx | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

(limited to 'src/index.tsx')

diff --git a/src/index.tsx b/src/index.tsx
index 98be8a7..1362544 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -43,10 +43,19 @@ const App: React.FC = () => {
       <Header setPage={setPage} />
       <div className={classes.root}>
         {
-          // eslint-disable-next-line
-          page === 'profile' && (!user ? <SignInForm setUser={setUser} /> : <ProfileInfo id={user?._id || ''} setUser={setUser} />)
+          page === 'profile'
+            ? (
+              user
+                ? (
+                  <>
+                    <ProfileInfo id={user?._id || ''} setUser={setUser} />
+                    <Feed page={page} />
+                  </>
+                )
+                : <SignInForm setUser={setUser} />
+            )
+            : <Feed page={page} />
         }
-        <Feed page={page} />
       </div>
     </ThemeProvider>
   );
-- 
cgit v1.2.3


From 3cff0821a8989afca1effb5420d8d0d55d513dbf Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sun, 14 Jun 2020 15:35:04 +0300
Subject: fix: fetch user correctly

---
 src/index.tsx | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

(limited to 'src/index.tsx')

diff --git a/src/index.tsx b/src/index.tsx
index 1362544..0855038 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -1,4 +1,4 @@
-import React, { useState } from 'react';
+import React, { useState, useEffect } from 'react';
 import ReactDOM from 'react-dom';
 import {
   createMuiTheme,
@@ -15,6 +15,7 @@ import ProfileInfo from './ProfileInfo/ProfileInfo';
 
 import SignInForm from './Form/SignInForm';
 import { User } from './types';
+import { get } from './requests';
 
 const theme = createMuiTheme({
   palette: {
@@ -37,6 +38,15 @@ const App: React.FC = () => {
   const [user, setUser] = React.useState<User | undefined>();
   const classes = useStyles();
 
+  useEffect(() => {
+    const userId = localStorage.getItem('userId');
+    if (userId) {
+      get(`/users/${userId}`).then(response => {
+        setUser(response.data);
+      });
+    }
+  }, []);
+
   return (
     <ThemeProvider theme={theme}>
       <CssBaseline />
-- 
cgit v1.2.3

