Profile and logout buttons are disabled when logged out

This commit is contained in:
2019-05-24 09:44:24 +10:00
parent 4fe34a62e8
commit 38cc4fec1a
+35 -3
View File
@@ -1,5 +1,6 @@
import React from 'react';
import { withRouter, Link } from 'react-router-dom';
import { connect } from 'react-redux';
import Logout from './logout.jsx';
@@ -12,26 +13,57 @@ class CommonLinks extends React.Component {
}
render() {
//render extra stuff
let Extra;
if (this.props.extra) {
Extra = this.props.extra;
} else {
Extra = () => null;
}
//disable the profile link when logged out
let ProfileLink;
if (this.props.loggedIn) {
ProfileLink = () => <p>Go to <Link to='/profile' onClick={this.props.onClickProfile}>your profile</Link></p>;
} else {
ProfileLink = () => null;
}
//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>Return <Link to='/' onClick={this.props.onClickHome}>home</Link></p>
<p>Go to <Link to='/profile' onClick={this.props.onClickProfile}>your profile</Link></p>
<ProfileLink />
<p>Go to <Link to='/ladder' onClick={this.props.onClickLadder}>the game ladder</Link></p>
<Extra />
<Logout onClick={() => this.props.history.push('/')} />
<LogoutLink />
</div>
);
}
}
function mapStoreToProps(store) {
return {
loggedIn: store.account.id !== 0
}
}
function mapDispatchToProps(dispatch) {
return {
//
}
}
CommonLinks = connect(mapStoreToProps, mapDispatchToProps)(CommonLinks);
export default withRouter(CommonLinks);