|
1 | 1 | import React from 'react';
|
2 |
| -import './NavBar.less' |
| 2 | +import './NavBar.less'; |
3 | 3 | import config from './NavBarConfig.json';
|
4 |
| -import Logo from "../../assets/casmm_logo.png"; |
5 |
| -import { Link, useHistory } from "react-router-dom"; |
6 |
| -import {Menu, Dropdown} from 'antd'; |
7 |
| -import {DownOutlined} from '@ant-design/icons'; |
8 |
| -import { getUser, removeUserSession } from "../../Utils/AuthRequests"; |
| 4 | +import Logo from '../../assets/casmm_logo.png'; |
| 5 | +import { Link, useHistory } from 'react-router-dom'; |
| 6 | +import { Menu, Dropdown } from 'antd'; |
| 7 | +import { DownOutlined } from '@ant-design/icons'; |
| 8 | +import { getUser, removeUserSession } from '../../Utils/AuthRequests'; |
9 | 9 |
|
10 | 10 | export default function NavBar(props) {
|
11 |
| - const {isMentor, isStudent, isContentCreator } = props; |
12 |
| - const user = getUser(); |
13 |
| - let currentRoute = window.location.pathname; |
14 |
| - let profile = ""; |
15 |
| - let history = useHistory(); |
16 |
| - let routes = config.routes; |
| 11 | + const { isMentor, isStudent, isContentCreator } = props; |
| 12 | + const user = getUser(); |
| 13 | + let currentRoute = window.location.pathname; |
| 14 | + let profile = ''; |
| 15 | + let history = useHistory(); |
| 16 | + let routes = config.routes; |
17 | 17 |
|
18 |
| - if (isMentor) { |
19 |
| - profile = "isMentor" |
20 |
| - } else if (isStudent) { |
21 |
| - profile = "isStudent" |
22 |
| - } else if (isContentCreator) { |
23 |
| - profile = "isContentCreator" |
24 |
| - } else { |
25 |
| - profile = "defaultUser" |
26 |
| - } |
| 18 | + if (isMentor) { |
| 19 | + profile = 'isMentor'; |
| 20 | + } else if (isStudent) { |
| 21 | + profile = 'isStudent'; |
| 22 | + } else if (isContentCreator) { |
| 23 | + profile = 'isContentCreator'; |
| 24 | + } else { |
| 25 | + profile = 'defaultUser'; |
| 26 | + } |
27 | 27 |
|
28 |
| - const handleLogout = () => { |
29 |
| - removeUserSession(); |
30 |
| - history.push('/'); |
31 |
| - }; |
| 28 | + const handleLogout = () => { |
| 29 | + removeUserSession(); |
| 30 | + history.push('/'); |
| 31 | + }; |
32 | 32 |
|
33 |
| - const handleRouteChange = (route) => { |
34 |
| - history.push(route); |
35 |
| - } |
| 33 | + const handleRouteChange = (route) => { |
| 34 | + history.push(route); |
| 35 | + }; |
36 | 36 |
|
37 |
| - const shouldShowRoute = (route) => { |
38 |
| - if (currentRoute === routes[route]) return false; |
39 |
| - return config.users[profile].includes(route); |
40 |
| - } |
| 37 | + const shouldShowRoute = (route) => { |
| 38 | + if (currentRoute === routes[route]) return false; |
| 39 | + return config.users[profile].includes(route); |
| 40 | + }; |
41 | 41 |
|
42 |
| - const menu = |
43 |
| - <Menu> |
44 |
| - { shouldShowRoute("Home") ? <Menu.Item key="0" onClick={() => handleRouteChange(routes.Home)}> |
45 |
| - <i className="fa fa-home"/> |
46 |
| - Home |
47 |
| - </Menu.Item> : null } |
48 |
| - {/*{ shouldShowRoute("AccountInfo") ? <Menu.Item key="0" onClick={() => handleRouteChange(routes.AccountInfo)}>*/} |
49 |
| - {/* <i className="fa fa-user-circle"/>*/} |
50 |
| - {/* Account Info*/} |
51 |
| - {/*</Menu.Item> : null}*/} |
52 |
| - { shouldShowRoute("Dashboard") ? <Menu.Item key="1" onClick={() => handleRouteChange(routes.Dashboard)}> |
53 |
| - <i className="fa fa-home"/> |
54 |
| - Dashboard |
55 |
| - </Menu.Item> : null } |
56 |
| - { shouldShowRoute("ContentCreatorDashboard") ? <Menu.Item key="1" onClick={() => handleRouteChange(routes.ContentCreatorDashboard)}> |
57 |
| - <i className="fa fa-home"/> |
58 |
| - Dashboard |
59 |
| - </Menu.Item> : null } |
60 |
| - { shouldShowRoute("Sandbox") ? <Menu.Item key="1" onClick={() => handleRouteChange(routes.Sandbox)}> |
61 |
| - <i className="fa fa-window-maximize"/> |
62 |
| - Sandbox |
63 |
| - </Menu.Item> : null } |
64 |
| - { shouldShowRoute("TeacherLogin") ? <Menu.Item key="2" onClick={() => handleRouteChange(routes.TeacherLogin)}> |
65 |
| - <i className="fa fa-sign-in-alt"/> |
66 |
| - User Login |
67 |
| - </Menu.Item> : null } |
68 |
| - { shouldShowRoute("About") ? <Menu.Item key="3" onClick={() => handleRouteChange(routes.About)}> |
69 |
| - <i className="fa fa-info-circle"/> |
70 |
| - About |
71 |
| - </Menu.Item> : null } |
72 |
| - { shouldShowRoute("SignOut") ? <Menu.Item key="2" onClick={() => handleLogout()}> |
73 |
| - <i className="fa fa-sign-out-alt"/> |
74 |
| - Sign Out |
75 |
| - </Menu.Item> : null } |
76 |
| - </Menu> |
| 42 | + const menu = ( |
| 43 | + <Menu> |
| 44 | + {shouldShowRoute('Home') ? ( |
| 45 | + <Menu.Item key='0' onClick={() => handleRouteChange(routes.Home)}> |
| 46 | + <i className='fa fa-home' /> |
| 47 | + Home |
| 48 | + </Menu.Item> |
| 49 | + ) : null} |
| 50 | + {/*{ shouldShowRoute("AccountInfo") ? <Menu.Item key="0" onClick={() => handleRouteChange(routes.AccountInfo)}>*/} |
| 51 | + {/* <i className="fa fa-user-circle"/>*/} |
| 52 | + {/* Account Info*/} |
| 53 | + {/*</Menu.Item> : null}*/} |
| 54 | + {shouldShowRoute('Dashboard') ? ( |
| 55 | + <Menu.Item key='1' onClick={() => handleRouteChange(routes.Dashboard)}> |
| 56 | + <i className='fa fa-home' /> |
| 57 | + Dashboard |
| 58 | + </Menu.Item> |
| 59 | + ) : null} |
| 60 | + {shouldShowRoute('ContentCreatorDashboard') ? ( |
| 61 | + <Menu.Item |
| 62 | + key='1' |
| 63 | + onClick={() => handleRouteChange(routes.ContentCreatorDashboard)} |
| 64 | + > |
| 65 | + <i className='fa fa-home' /> |
| 66 | + Dashboard |
| 67 | + </Menu.Item> |
| 68 | + ) : null} |
| 69 | + {shouldShowRoute('Sandbox') ? ( |
| 70 | + <Menu.Item key='1' onClick={() => handleRouteChange(routes.Sandbox)}> |
| 71 | + <i className='fa fa-window-maximize' /> |
| 72 | + Sandbox |
| 73 | + </Menu.Item> |
| 74 | + ) : null} |
| 75 | + {shouldShowRoute('TeacherLogin') ? ( |
| 76 | + <Menu.Item |
| 77 | + key='2' |
| 78 | + onClick={() => handleRouteChange(routes.TeacherLogin)} |
| 79 | + > |
| 80 | + <i className='fa fa-sign-in-alt' /> |
| 81 | + User Login |
| 82 | + </Menu.Item> |
| 83 | + ) : null} |
| 84 | + {shouldShowRoute('About') ? ( |
| 85 | + <Menu.Item key='3' onClick={() => handleRouteChange(routes.About)}> |
| 86 | + <i className='fa fa-info-circle' /> |
| 87 | + About |
| 88 | + </Menu.Item> |
| 89 | + ) : null} |
| 90 | + {shouldShowRoute('BugReport') ? ( |
| 91 | + <Menu.Item key='2' onClick={() => handleRouteChange(routes.BugReport)}> |
| 92 | + <i className='fa fa-calendar-times' /> |
| 93 | + Report a Bug |
| 94 | + </Menu.Item> |
| 95 | + ) : null} |
| 96 | + {shouldShowRoute('SignOut') ? ( |
| 97 | + <Menu.Item key='3' onClick={() => handleLogout()}> |
| 98 | + <i className='fa fa-sign-out-alt' /> |
| 99 | + Sign Out |
| 100 | + </Menu.Item> |
| 101 | + ) : null} |
| 102 | + </Menu> |
| 103 | + ); |
77 | 104 |
|
78 |
| - return ( |
79 |
| - <span id="navBar"> |
80 |
| - <Link id='link' to={isMentor ? "/dashboard" : "/"}> |
81 |
| - <img src={Logo} id='casmm-logo' alt='logo'/> |
82 |
| - </Link> |
83 |
| - <div id="dropdown-menu"> |
84 |
| - <Dropdown overlay={menu} trigger={['click']}> |
85 |
| - <button className="ant-dropdown-link" onClick={e => e.preventDefault()}> |
86 |
| - {isMentor ? user.username : "Menu"} <DownOutlined/> |
87 |
| - </button> |
88 |
| - </Dropdown> |
89 |
| - </div> |
90 |
| - </span> |
91 |
| - ) |
| 105 | + return ( |
| 106 | + <span id='navBar'> |
| 107 | + <Link id='link' to={isMentor ? '/dashboard' : '/'}> |
| 108 | + <img src={Logo} id='casmm-logo' alt='logo' /> |
| 109 | + </Link> |
| 110 | + <div id='dropdown-menu'> |
| 111 | + <Dropdown overlay={menu} trigger={['click']}> |
| 112 | + <button |
| 113 | + className='ant-dropdown-link' |
| 114 | + onClick={(e) => e.preventDefault()} |
| 115 | + > |
| 116 | + {isMentor ? user.username : 'Menu'} <DownOutlined /> |
| 117 | + </button> |
| 118 | + </Dropdown> |
| 119 | + </div> |
| 120 | + </span> |
| 121 | + ); |
92 | 122 | }
|
0 commit comments