From c311c538a3442aed8d77449736f28be66feea57c Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sun, 14 Jun 2020 22:42:52 +0300
Subject: feat: configure navigation

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

(limited to 'src/index.tsx')

diff --git a/src/index.tsx b/src/index.tsx
index 55bf773..d7326cb 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -13,9 +13,10 @@ import Header from './components/Header/Header';
 import ProfilePage from './pages/ProfilePage/ProfilePage';
 import FeedPage from './pages/FeedPage/FeedPage';
 import AuthPage from './pages/AuthPage/AuthPage';
-import { User } from './types';
+import { User, Page } from './types';
 import { get } from './requests';
 
+
 const theme = createMuiTheme({
   palette: {
     primary: {
@@ -33,13 +34,25 @@ const useStyles = makeStyles({
 });
 
 const App: React.FC = () => {
-  const [page, setPage] = useState('feed');
   const [user, setUser] = React.useState<User | undefined>();
+  const [page, setPage] = useState<Page>({ prefix: 'feed', id: '' });
   const classes = useStyles();
 
+  const navigate = (prefix: string, id?: string): void => {
+    if (prefix === 'profile' && !id && !user) setPage({
+      prefix: 'auth',
+      id: ''
+    });
+    else setPage({
+      prefix,
+      id: (id || user?._id || '')
+    });
+  };
+
   const logOut = () => {
     localStorage.removeItem('userId');
     setUser(undefined);
+    navigate('auth');
   };
 
   useEffect(() => {
@@ -54,17 +67,11 @@ const App: React.FC = () => {
   return (
     <ThemeProvider theme={theme}>
       <CssBaseline />
-      <Header setPage={setPage} />
+      <Header navigate={navigate} />
       <div className={classes.root}>
-        {
-          page === 'profile'
-            ? (
-              user
-                ? <ProfilePage logOut={logOut} id={user?._id} />
-                : <AuthPage setUser={setUser} />
-            )
-            : <FeedPage />
-        }
+        { page.prefix === 'profile' && <ProfilePage logOut={logOut} id={page.id} navigate={navigate} /> }
+        { page.prefix === 'feed' && <FeedPage navigate={navigate} /> }
+        { page.prefix === 'auth' && <AuthPage setUser={setUser} navigate={navigate}/> }
       </div>
     </ThemeProvider>
   );
-- 
cgit v1.2.3


From 2a65284a385915818ca5f3e3b7354554e19af9cb Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Mon, 15 Jun 2020 15:52:40 +0300
Subject: style: fix eslint errors

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

(limited to 'src/index.tsx')

diff --git a/src/index.tsx b/src/index.tsx
index d7326cb..876491d 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -39,14 +39,17 @@ const App: React.FC = () => {
   const classes = useStyles();
 
   const navigate = (prefix: string, id?: string): void => {
-    if (prefix === 'profile' && !id && !user) setPage({
-      prefix: 'auth',
-      id: ''
-    });
-    else setPage({
-      prefix,
-      id: (id || user?._id || '')
-    });
+    if (prefix === 'profile' && !id && !user) {
+      setPage({
+        prefix: 'auth',
+        id: ''
+      });
+    } else {
+      setPage({
+        prefix,
+        id: (id || user?._id || '')
+      });
+    }
   };
 
   const logOut = () => {
@@ -71,7 +74,7 @@ const App: React.FC = () => {
       <div className={classes.root}>
         { page.prefix === 'profile' && <ProfilePage logOut={logOut} id={page.id} navigate={navigate} /> }
         { page.prefix === 'feed' && <FeedPage navigate={navigate} /> }
-        { page.prefix === 'auth' && <AuthPage setUser={setUser} navigate={navigate}/> }
+        { page.prefix === 'auth' && <AuthPage setUser={setUser} navigate={navigate} /> }
       </div>
     </ThemeProvider>
   );
-- 
cgit v1.2.3

