Simplified CommonLinks

This commit is contained in:
2019-05-26 23:46:05 +10:00
parent 972a3a7ea7
commit c569d99aed
4 changed files with 54 additions and 66 deletions
+36 -27
View File
@@ -1,6 +1,7 @@
import React from 'react';
import { withRouter, Link } from 'react-router-dom';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import Logout from './logout.jsx';
@@ -21,38 +22,46 @@ class CommonLinks extends React.Component {
Extra = () => null;
}
//disable the profile link when logged out
let ProfileLink;
//if logged in
if (this.props.loggedIn) {
ProfileLink = () => <p><Link to='/profile' onClick={this.props.onClickProfile}>Your Profile</Link></p>;
} else {
ProfileLink = () => null;
return (
<div className='panel'>
<p><Link to='/' onClick={this.props.onClickHome}>Return Home</Link></p>
<p><Link to='/profile' onClick={this.props.onClickProfile}>Your Profile</Link></p>
<p><Link to='/ladder' onClick={this.props.onClickLadder}>Game Ladder</Link></p>
<p><Link to='/passwordchange' onClick={this.props.onClickPasswordChange}>Change Password</Link></p>
<Extra />
<Logout onClick={() => this.props.history.push('/')} />
</div>
);
} else { //if not logged in
return (
<div className='panel'>
<p><Link to='/signup' onClick={this.props.onClickSignup}>Sign Up</Link></p>
<p><Link to='/login' onClick={this.props.onClickLogin}>Login</Link></p>
<p><Link to='/passwordrecover' onClick={this.props.onClickPasswordRecover}>Recover Password</Link></p>
<p><Link to='/' onClick={this.props.onClickHome}>Return Home</Link></p>
<p><Link to='/ladder' onClick={this.props.onClickLadder}>Game Ladder</Link></p>
<Extra />
</div>
);
}
//disable the logout button when logged out
let LogoutLink;
if (this.props.loggedIn) {
LogoutLink = () => <Logout onClick={() => this.props.history.push('/')} />;
} else {
LogoutLink = () => null;
}
return (
<div className='panel'>
<p><Link to='/' onClick={this.props.onClickHome}>Return Home</Link></p>
<ProfileLink />
<p><Link to='/ladder' onClick={this.props.onClickLadder}>Game Ladder</Link></p>
<p><Link to='/passwordchange' onClick={this.props.onClickLadder}>Change Password</Link></p>
<Extra />
<LogoutLink />
</div>
);
}
}
CommonLinks.propTypes = {
onClickSignup: PropTypes.func,
onClickLogin: PropTypes.func,
onClickPasswordRecover: PropTypes.func,
onClickHome: PropTypes.func,
onClickProfile: PropTypes.func,
onClickLadder: PropTypes.func,
onClickPasswordChange: PropTypes.func
};
function mapStoreToProps(store) {
return {
loggedIn: store.account.id !== 0
+1 -1
View File
@@ -15,7 +15,7 @@ class NewsPanel extends React.Component {
render() {
return (
<div>
{Object.keys(this.state.data).map((key) => <div key={key}><ReactMarkdown source={this.state.data[key]} escapeHTML={false} /><hr /></div> )}
{Object.keys(this.state.data).map((key) => <div key={key}><ReactMarkdown source={this.state.data[key]} escapeHTML={false} /><hr className='newsLine' /></div> )}
</div>
);
}