summaryrefslogtreecommitdiff
path: root/frontend/src/components/navigation/Navbar.js
blob: 164a23091ee688c52b8fbd9acf540db4366cf62a (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
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.sass'

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 clickable', location.pathname === route ? 'active' : undefined)}>{children}</li>
)

const LoggedInSectionWithoutRoute = ({ location }) => (
    <ul className="navbar-nav auth-links">
        {userIsLoggedIn() ? (
            [
                location.pathname === '/' ? (
                    <NavItem route="/projects" key="projects">
                        <Link className="nav-link" title="My Projects" to="/projects">
                            My Projects
                        </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