|
@@ -1,6 +1,6 @@
|
|
-import React from 'react'
|
|
|
|
|
|
+import React, { useEffect, useState } from 'react'
|
|
import { Router, Route, Redirect, withRouter, Switch } from 'react-router-dom';
|
|
import { Router, Route, Redirect, withRouter, Switch } from 'react-router-dom';
|
|
-import { Provider } from 'react-redux';
|
|
|
|
|
|
+import { Provider, useSelector } from 'react-redux';
|
|
import { store } from './components/redux/index';
|
|
import { store } from './components/redux/index';
|
|
import createHistory from "history/createBrowserHistory";
|
|
import createHistory from "history/createBrowserHistory";
|
|
|
|
|
|
@@ -17,6 +17,7 @@ import AuthReg from './components/auth_reg';
|
|
import { CHeader } from './components/structure/header';
|
|
import { CHeader } from './components/structure/header';
|
|
import Footer from './components/structure/footer';
|
|
import Footer from './components/structure/footer';
|
|
import Search from './components/search';
|
|
import Search from './components/search';
|
|
|
|
+import Page404 from './components/404/page404';
|
|
|
|
|
|
// url проекта
|
|
// url проекта
|
|
export const url = 'http://hipstagram.node.ed.asmer.org.ua/graphql'
|
|
export const url = 'http://hipstagram.node.ed.asmer.org.ua/graphql'
|
|
@@ -24,6 +25,7 @@ export const url = 'http://hipstagram.node.ed.asmer.org.ua/graphql'
|
|
const history = createHistory()
|
|
const history = createHistory()
|
|
|
|
|
|
|
|
|
|
|
|
+// Приватный роутинг - удалить, если не буду использовать
|
|
|
|
|
|
{
|
|
{
|
|
// фейковый авторизатор
|
|
// фейковый авторизатор
|
|
@@ -39,6 +41,8 @@ const history = createHistory()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
// кнопка разлогина, которая рисуется, если залогинен
|
|
// кнопка разлогина, которая рисуется, если залогинен
|
|
const AuthButton = withRouter(({ history }) => (
|
|
const AuthButton = withRouter(({ history }) => (
|
|
fakeAuth.isAuthenticated && (
|
|
fakeAuth.isAuthenticated && (
|
|
@@ -49,53 +53,47 @@ const history = createHistory()
|
|
</p>
|
|
</p>
|
|
)
|
|
)
|
|
))
|
|
))
|
|
-}
|
|
|
|
|
|
|
|
|
|
+ const PrivateRoute = ({ component: Component, ...rest }) => (
|
|
|
|
+ <Route {...rest} render={(props) => (
|
|
|
|
+ typeof localStorage.authToken === 'string'
|
|
|
|
+ ? <Component {...props} />
|
|
|
|
+ : <Redirect to={{
|
|
|
|
+ pathname: '/authorization',
|
|
|
|
+ state: { from: props.location }
|
|
|
|
+ }} />
|
|
|
|
+ )} />
|
|
|
|
+ )
|
|
|
|
|
|
|
|
|
|
-const Page404 = () =>
|
|
|
|
- <div>
|
|
|
|
- NOT FOUND
|
|
|
|
- </div>
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// Приватный роутинг
|
|
|
|
-const PrivateRoute = ({ component: Component, ...rest }) => (
|
|
|
|
- <Route {...rest} render={(props) => (
|
|
|
|
- typeof localStorage.authToken === 'string'
|
|
|
|
- ? <Component {...props} />
|
|
|
|
- : <Redirect to={{
|
|
|
|
- pathname: '/authorization',
|
|
|
|
- state: { from: props.location }
|
|
|
|
- }} />
|
|
|
|
- )} />
|
|
|
|
-)
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-const MyRoutes = () =>
|
|
|
|
- // <>
|
|
|
|
- <Switch>
|
|
|
|
- {/* <PrivateRoute path="/" component={CFeed} exact /> */}
|
|
|
|
- {/* <Route path="/" component={
|
|
|
|
- store.getState()?.auth?.token ? CFeed : Authorization
|
|
|
|
- } exact
|
|
|
|
- /> */}
|
|
|
|
- <Route path="/" component={
|
|
|
|
- store.getState()?.auth?.token ? CFeed : AuthReg
|
|
|
|
- } exact
|
|
|
|
- />
|
|
|
|
-
|
|
|
|
- {/* <Route path="/authorization" component={Authorization} /> */}
|
|
|
|
- {/* <Route path="/registration" component={Registration2} /> */}
|
|
|
|
- <Route path="/registration" component={AuthReg} />
|
|
|
|
- <Route path="/post/:postId" component={CComments} />
|
|
|
|
- <Route path="/user/:userId" component={CUser} />
|
|
|
|
- <Route path="/createpost" component={CreatePost} />
|
|
|
|
- <Route path='/search' component={Search} />
|
|
|
|
- <Route path="*" component={Page404} />
|
|
|
|
- </Switch>
|
|
|
|
-{/* </> */ }
|
|
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// роутинг в зависимости от того.залогинен пользователь или нет
|
|
|
|
+const MainRoutes = () => {
|
|
|
|
+ const currentState = useSelector(state => state?.auth?.token)
|
|
|
|
+
|
|
|
|
+ return (
|
|
|
|
+ <main style={{ flexGrow: '1' }}>
|
|
|
|
+ {currentState
|
|
|
|
+ ? <Switch>
|
|
|
|
+ <Route path="/" component={CFeed} exact />
|
|
|
|
+ <Route path="/post/:postId" component={CComments} />
|
|
|
|
+ <Route path="/user/:userId" component={CUser} />
|
|
|
|
+ <Route path="/createpost" component={CreatePost} />
|
|
|
|
+ <Route path='/search' component={Search} />
|
|
|
|
+ <Route path="*" component={Page404} />
|
|
|
|
+ </Switch>
|
|
|
|
+ : <Switch>
|
|
|
|
+ <Route path="/" component={AuthReg} exact />
|
|
|
|
+ <Route path="/registration" component={AuthReg} />
|
|
|
|
+ <Route path="/post/:postId" component={CComments} />
|
|
|
|
+ <Route path="/user/:userId" component={CUser} />
|
|
|
|
+ <Route path="*" component={Page404} />
|
|
|
|
+ </Switch>
|
|
|
|
+ }
|
|
|
|
+ </main>
|
|
|
|
+ )
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
export default function App() {
|
|
export default function App() {
|
|
@@ -104,49 +102,11 @@ export default function App() {
|
|
<Router history={history}>
|
|
<Router history={history}>
|
|
<div className="wrapper">
|
|
<div className="wrapper">
|
|
<CHeader />
|
|
<CHeader />
|
|
- <main style={{ flexGrow: '1' }}>
|
|
|
|
- <Switch>
|
|
|
|
- <MyRoutes />
|
|
|
|
- </Switch>
|
|
|
|
- </main>
|
|
|
|
|
|
+ <MainRoutes />
|
|
<Footer />
|
|
<Footer />
|
|
</div>
|
|
</div>
|
|
</Router>
|
|
</Router>
|
|
</Provider>
|
|
</Provider>
|
|
|
|
|
|
)
|
|
)
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// export default function App() {
|
|
|
|
-// return (
|
|
|
|
-// <Provider store={store}>
|
|
|
|
-// <Router history={history}>
|
|
|
|
-// <div className="wrapper">
|
|
|
|
-// <CHeader />
|
|
|
|
-// <main style={{ flexGrow: '1' }}>
|
|
|
|
-// <Switch>
|
|
|
|
-// {/* <PrivateRoute path="/" component={CFeed} exact /> */}
|
|
|
|
-// <Route path="/" component={
|
|
|
|
-// store.getState()?.auth?.token ? CFeed : Authorization
|
|
|
|
-// } exact
|
|
|
|
-// />
|
|
|
|
-
|
|
|
|
-// <Route path="/authorization" component={Authorization} />
|
|
|
|
-// <Route path="/registration" component={Registration} />
|
|
|
|
-// <Route path="/post/:postId" component={CComments} />
|
|
|
|
-// <Route path="/user/:userId" component={CUser} />
|
|
|
|
-// <Route path="/createpost" component={CreatePost} />
|
|
|
|
-// <Route path='/search' component={Search} />
|
|
|
|
-// <Route path="*" component={Page404} />
|
|
|
|
-// </Switch>
|
|
|
|
-// </main>
|
|
|
|
-// <Footer />
|
|
|
|
-// </div>
|
|
|
|
-// </Router>
|
|
|
|
-// </Provider>
|
|
|
|
-
|
|
|
|
-// )
|
|
|
|
-// }
|
|
|
|
|
|
+}
|