blob: 444589492ecbf7ae6b98d92af107f764c4fd09e3 (
plain)
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
97
98
99
100
101
102
|
import classNames from "classnames";
import React from "react";
import { Link, withRouter } from "react-router-dom";
import { userIsLoggedIn } from "../../auth/index";
import Login from "../../containers/auth/Login";
import Logout from "../../containers/auth/Logout";
import ProfileName from "../../containers/auth/ProfileName";
import "./Navbar.css";
export const NAVBAR_HEIGHT = 60;
export const NavItem = withRouter(props => <NavItemWithoutRoute {...props} />);
export const LoggedInSection = withRouter(props => (
<LoggedInSectionWithoutRoute {...props} />
));
const GitHubLink = () => (
<a
href="https://github.com/atlarge-research/opendc"
className="ml-2 mr-3 text-dark"
style={{ position: "relative", top: 7 }}
>
<span className="fa fa-github fa-2x" />
</a>
);
const NavItemWithoutRoute = ({ route, location, children }) => (
<li
className={classNames(
"nav-item",
location.pathname === route ? "active" : undefined
)}
>
{children}
</li>
);
const LoggedInSectionWithoutRoute = ({ location }) => (
<ul className="navbar-nav auth-links">
{userIsLoggedIn() ? (
[
location.pathname === "/" ? (
<NavItem route="/simulations" key="simulations">
<Link className="nav-link" title="My Simulations" to="/simulations">
My Simulations
</Link>
</NavItem>
) : (
<NavItem route="/profile" key="profile">
<Link className="nav-link" title="My Profile" to="/profile">
<ProfileName />
</Link>
</NavItem>
),
<NavItem route="logout" key="logout">
<Logout />
</NavItem>
]
) : (
<NavItem route="login">
<GitHubLink />
<Login visible={true} />
</NavItem>
)}
</ul>
);
const Navbar = ({ fullWidth, children }) => (
<nav
className="navbar fixed-top navbar-expand-lg navbar-light bg-faded"
id="navbar"
>
<div className={fullWidth ? "container-fluid" : "container"}>
<button
className="navbar-toggler navbar-toggler-right"
type="button"
data-toggle="collapse"
data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span className="navbar-toggler-icon" />
</button>
<Link
className="navbar-brand opendc-brand"
to="/"
title="OpenDC"
onClick={() => window.scrollTo(0, 0)}
>
<img src="/img/logo.png" alt="OpenDC" />
</Link>
<div className="collapse navbar-collapse" id="navbarSupportedContent">
<ul className="navbar-nav mr-auto">{children}</ul>
<LoggedInSection />
</div>
</div>
</nav>
);
export default Navbar;
|