-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
96 lines (87 loc) · 2.97 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import React from 'react';
import {Switch,BrowserRouter as Router,Route} from 'react-router-dom';
import LandingPage from './Components/Pages/LandingPage/LandingPage';
import Admin from './Components/AdminScreen';
import PrivateRoute from './Components/Route/PrivateRoutes';
import {useAuth} from './Components/Provider/authProvider';
import BookList from './Components/BookListScreen';
import Profile from './Components/ProfileScreen';
import Navbar from './Components/NavbarScreen';
import MyLibrary from './Components/Pages/MyLibrary/MyLibrary';
import AddBookUser from './Components/AddBookScreen';
import DetailBook from './Components/DetailBookScreen';
import SideBar from './Components/SideBarScreen';
import Reader from './Components/readerScreen';
import Categories from './Components/CategoryScreen';
import NoPage from './Components/NoPage'
const userRoute = [
{
path:'/home',
component:BookList
},
{
path:'/profile',
component:Profile
},
{
path:'/mylibrary',
component:MyLibrary
},
{
path:'/addbook',
component:AddBookUser
},
{
path:'/detail/:id',
component:DetailBook
},
{
path:'/read/:id',
component:Reader
},
{
path:'/admin',
component:Admin
},
{
path:'/category',
component:Categories,
}
]
function App() {
const {state:authState} = useAuth();
const {userInfo} = authState;
return (
<Router>
<Switch>
<Route exact path='/' component={LandingPage}/>
<Route path={['/home','/profile','/mylibrary','/addbook','/detail/:id','/read/:id','/admin','/category']}>
<div className={userInfo && !userInfo.isAdmin ? "container-fluid" : null}>
<div className={userInfo && userInfo.isAdmin ? '' : 'row pages-container'}>
{userInfo && userInfo.isAdmin ?
<div>
<Navbar/>
</div>
:
<div className='col-2 sidebar'>
<SideBar/>
</div>
}
<div className={userInfo && !userInfo.isAdmin ? 'col-10 pages-right' : ''}>
<Switch>
{userRoute.map ( ({path,component},key) =>{
return(
<PrivateRoute exact path={path} component={component} key={key}/>
)
})}
</Switch>
</div>
</div>
</div>
</Route>
<Route path="*" component={NoPage}/>
</Switch>
</Router>
);
}
export default App;