-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathNavbar.js
196 lines (175 loc) · 5.44 KB
/
Navbar.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import React, { Component } from 'react';
import { Link, Redirect } from 'react-router-dom';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { loginUser, logoutUser } from '../../actions/authActions';
import {
Button,
Form,
FormGroup,
Label,
Input,
Collapse,
Navbar,
NavbarToggler,
NavbarBrand,
Nav,
NavItem,
NavLink,
UncontrolledDropdown,
DropdownToggle,
DropdownMenu,
DropdownItem,
Container
} from 'reactstrap';
class NavbarClass extends Component {
constructor() {
super();
this.state = {
signInEmail: "",
signInpassword: "",
loginShow: true,
navbarIsOpen: false
};
this.toggle = this.toggle.bind(this);
this.onSignIn = this.onSignIn.bind(this);
this.onTextboxChangeSignInEmail = this.onTextboxChangeSignInEmail.bind(this);
this.onTextboxChangeSignInPassword = this.onTextboxChangeSignInPassword.bind(this);
};
componentDidMount() {
// <Redirect to="/" />
}
onTextboxChangeSignInPassword(event) {
event.preventDefault();
this.setState({
signInPassword: event.target.value,
});
}
onTextboxChangeSignInEmail(event) {
event.preventDefault();
this.setState({
signInEmail: event.target.value,
});
}
onSignIn(event) {
event.preventDefault();
const user = {
email: this.state.signInEmail,
password: this.state.signInPassword
};
this.props.loginUser(user);
}
onLogoutClick(event) {
event.preventDefault();
// this.forceUpdate();
this.props.logoutUser();
}
reload() {
// this.forceUpdate();
// window.location.reload();
}
toggle() {
this.setState({
navbarIsOpen: !this.state.navbarIsOpen
});
}
render() {
var isAuthenticated = this.props.auth.isAuthenticated;
var displayName = (this.props.auth.name && this.props.auth.name.firstName) || "";
const authLinks = (
<Collapse isOpen={this.state.navbarIsOpen} navbar>
<Nav className="mr-auto" navbar>
<NavItem>
<NavLink tag={Link} to="/contests" activeclassname="active">Contests</NavLink>
</NavItem>
<NavItem>
<NavLink tag={Link} to="/courses" activeclassname="active">Courses</NavLink>
</NavItem>
<NavItem>
<NavLink tag={Link} to="/assignments" activeclassname="active">Assignments</NavLink>
</NavItem>
</Nav>
<hr/>
<Nav className="ml-auto" navbar>
<NavItem>
<NavLink disabled active>
{displayName.split(" ", 1)[0]}
</NavLink>
</NavItem>
<NavItem>
<NavLink tag={Link} to="/profile" activeclassname="active">Profile</NavLink>
</NavItem>
<UncontrolledDropdown nav inNavbar>
<DropdownToggle nav caret >
{this.state.navbarIsOpen? "Options":""}
</DropdownToggle>
<DropdownMenu right>
<DropdownItem tag={Link} to="/contribute">
Contribute
</DropdownItem>
<DropdownItem divider />
<DropdownItem onClick={this.onLogoutClick.bind(this)}>
Logout
</DropdownItem>
</DropdownMenu>
</UncontrolledDropdown>
</Nav>
</Collapse>
);
const guestLinks = (
<Collapse isOpen={this.state.navbarIsOpen} navbar>
<Nav className="ml-auto" navbar>
<Form inline onSubmit={this.onSignIn}>
<FormGroup className="mb-2 mr-sm-2 mb-sm-0">
<Label for="email" hidden>Email</Label>
<Input type="text" name="email" id="email" placeholder="Email" required onChange={this.onTextboxChangeSignInEmail} />
</FormGroup>
{' '}
<FormGroup className="mb-2 mr-sm-2 mb-sm-0">
<Label for="Password" hidden>Password</Label>
<Input type="password" name="password" id="Password" placeholder="Password" required onChange={this.onTextboxChangeSignInPassword} />
</FormGroup>
{' '}
<Button color="dark">Login</Button>
</Form>
<UncontrolledDropdown nav inNavbar>
<DropdownToggle nav caret >
{this.state.navbarIsOpen ? "Options" : ""}
</DropdownToggle>
<DropdownMenu right>
<DropdownItem tag={Link} to="/contribute">
Contribute
</DropdownItem>
<DropdownItem divider />
<DropdownItem tag={Link} to="/forgotPassword">
Forgot Password
</DropdownItem>
<DropdownItem divider />
<DropdownItem tag={Link} to="/signup">
Signup
</DropdownItem>
</DropdownMenu>
</UncontrolledDropdown>
</Nav>
</Collapse>
);
return (
<Navbar color="navbar-dark fixed-top" dark expand="md" className="mb-4">
<Container className="pb-2 pt-2">
<NavbarBrand tag={Link} to="/">The Alcoding Club</NavbarBrand>
<NavbarToggler onClick={this.toggle} />
{isAuthenticated ? authLinks : guestLinks}
</Container>
</Navbar>
);
}
}
NavbarClass.propTypes = {
auth: PropTypes.object.isRequired,
logoutUser: PropTypes.func.isRequired,
loginUser: PropTypes.func.isRequired,
};
const mapStateToProps = state => ({
auth: state.auth,
});
export default connect(mapStateToProps, { loginUser, logoutUser })(NavbarClass);