Merge branch 'split_authmenu' of Asara/sudoscientist-js-frontend into auth
This commit is contained in:
commit
d44ba36112
2 changed files with 83 additions and 29 deletions
80
src/components/AuthMenu.js
Normal file
80
src/components/AuthMenu.js
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
import React, { Component } from 'react';
|
||||||
|
|
||||||
|
class AuthMenu extends Component {
|
||||||
|
constructor (props) {
|
||||||
|
super(props)
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
where_in_auth_menu: "username",
|
||||||
|
}
|
||||||
|
|
||||||
|
this.handleSignUpRequest = this.handleSignUpRequest.bind(this)
|
||||||
|
this.handleLogInAttempt = this.handleLogInAttempt.bind(this)
|
||||||
|
this.handleAccountCreation = this.handleAccountCreation.bind(this)
|
||||||
|
this.authMenu = this.authMenu.bind(this)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSignUpRequest() {
|
||||||
|
this.setState(state => ({
|
||||||
|
where_in_auth_menu: "email",
|
||||||
|
auth_menu_visible: true,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
handleLogInAttempt() {
|
||||||
|
this.setState(state => ({
|
||||||
|
where_in_auth_menu: "password",
|
||||||
|
auth_menu_visible: true,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
handleAccountCreation() {
|
||||||
|
this.setState(state => ({
|
||||||
|
where_in_auth_menu: "password",
|
||||||
|
auth_menu_visible: true,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
authMenu() {
|
||||||
|
if (!this.props.auth_menu_visible) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
switch(this.state.where_in_auth_menu) {
|
||||||
|
case 'username':
|
||||||
|
return (
|
||||||
|
<div className="ui menu dropdown" style={{display: "inline"}}>
|
||||||
|
<div className="ui left icon input">
|
||||||
|
<input type="text" placeholder="Username">
|
||||||
|
</input>
|
||||||
|
<i className="users icon"></i>
|
||||||
|
</div>
|
||||||
|
<div className="fluid ui buttons">
|
||||||
|
<button onClick={this.handleSignUpRequest} className="ui button">Sign Up</button>
|
||||||
|
<div className="or"></div>
|
||||||
|
<button onClick={this.handleLogInAttempt} className="ui positive button">Sign In</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
case 'password':
|
||||||
|
return (
|
||||||
|
<div className="ui menu dropdown" style={{display: "inline"}}>
|
||||||
|
<div className="ui left icon input">
|
||||||
|
<input type="text" placeholder="Password">
|
||||||
|
</input>
|
||||||
|
<i className="lock icon"></i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
this.authMenu(this.state.auth_menu_visible)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default (AuthMenu)
|
|
@ -1,32 +1,7 @@
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { NavLink } from 'react-router-dom';
|
import { NavLink } from 'react-router-dom';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
import AuthMenu from './AuthMenu';
|
||||||
function AuthMenu(props) {
|
|
||||||
if (!props.showMenu) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="ui menu dropdown" style={{display: "inline"}}>
|
|
||||||
<div className="ui left icon input">
|
|
||||||
<input type="text" placeholder="Username">
|
|
||||||
</input>
|
|
||||||
<i className="users icon"></i>
|
|
||||||
</div>
|
|
||||||
<div className="ui left icon input">
|
|
||||||
<input type="text" placeholder="Password">
|
|
||||||
</input>
|
|
||||||
<i className="lock icon"></i>
|
|
||||||
</div>
|
|
||||||
<div className="fluid ui buttons">
|
|
||||||
<button className="ui button">Sign Up</button>
|
|
||||||
<div className="or"></div>
|
|
||||||
<button className="ui positive button">Sign In</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
class NavBar extends Component {
|
class NavBar extends Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
|
@ -34,14 +9,13 @@ class NavBar extends Component {
|
||||||
this.state = {
|
this.state = {
|
||||||
logged_in: false,
|
logged_in: false,
|
||||||
auth_menu_visible: false,
|
auth_menu_visible: false,
|
||||||
where_in_auth_menu: false,
|
|
||||||
}
|
}
|
||||||
this.handleLoginDropdown = this.handleLoginDropdown.bind(this)
|
this.handleLoginDropdown = this.handleLoginDropdown.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleLoginDropdown() {
|
handleLoginDropdown() {
|
||||||
this.setState(state => ({
|
this.setState(state => ({
|
||||||
auth_menu_visible: !state.auth_menu_visible
|
auth_menu_visible: true
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +29,7 @@ class NavBar extends Component {
|
||||||
<div onClick={this.handleLoginDropdown} className='item ui button dropdown'>
|
<div onClick={this.handleLoginDropdown} className='item ui button dropdown'>
|
||||||
Login
|
Login
|
||||||
<i className="dropdown icon"></i>
|
<i className="dropdown icon"></i>
|
||||||
<AuthMenu showMenu={this.state.auth_menu_visible}></AuthMenu>
|
<AuthMenu auth_menu_visible={this.state.auth_menu_visible}></AuthMenu>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Reference in a new issue