2021-05-31 18:23:25 +03:00
|
|
|
import React, { useState, useEffect, Suspense, lazy } from 'react';
|
2021-05-27 17:44:11 +03:00
|
|
|
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
|
|
|
|
import 'bootstrap/dist/css/bootstrap.min.css';
|
|
|
|
import './fonts/stylesheet.css';
|
2021-05-25 14:50:01 +03:00
|
|
|
|
2021-05-27 17:44:11 +03:00
|
|
|
const AuthPage = lazy(() => import('./pages/AuthPage'));
|
|
|
|
const HomePage = lazy(() => import('./pages/HomePage'));
|
|
|
|
const CandidatePage = lazy(() => import('./pages/CandidatePage'));
|
2021-05-26 13:35:57 +03:00
|
|
|
|
|
|
|
const App = () => {
|
2021-06-01 15:25:01 +03:00
|
|
|
const [isAuth, setIsAuth] = useState(true);
|
2021-05-31 13:40:49 +03:00
|
|
|
|
2021-05-31 18:23:25 +03:00
|
|
|
useEffect(() => {
|
|
|
|
const auth = localStorage.getItem('auth');
|
|
|
|
if (auth === 'true') {
|
|
|
|
setIsAuth(true);
|
|
|
|
}
|
|
|
|
}, []);
|
|
|
|
|
2021-05-25 14:50:01 +03:00
|
|
|
return (
|
2021-05-26 13:35:57 +03:00
|
|
|
<Router>
|
|
|
|
<Suspense fallback={<div>Loading...</div>}>
|
|
|
|
{isAuth ? (
|
|
|
|
<Switch>
|
2021-05-31 18:23:25 +03:00
|
|
|
<Route path="/" exact>
|
|
|
|
<HomePage />
|
|
|
|
</Route>
|
|
|
|
<Route path="/candidate/:id">
|
|
|
|
<CandidatePage />
|
|
|
|
</Route>
|
|
|
|
<Route>
|
|
|
|
<div>Not found page</div>
|
|
|
|
</Route>
|
2021-05-26 13:35:57 +03:00
|
|
|
</Switch>
|
|
|
|
) : (
|
2021-05-31 18:23:25 +03:00
|
|
|
<Route path="/" exact>
|
|
|
|
<AuthPage setAuth={setIsAuth} />
|
|
|
|
</Route>
|
2021-05-26 13:35:57 +03:00
|
|
|
)}
|
|
|
|
</Suspense>
|
|
|
|
</Router>
|
2021-05-27 17:44:11 +03:00
|
|
|
);
|
|
|
|
};
|
2021-05-25 14:50:01 +03:00
|
|
|
|
2021-05-27 17:44:11 +03:00
|
|
|
export default App;
|