Pull up signed in and username properties from EditButton to TournamentPage

This makes us able to provide these fields in lower components without having to
rebind the state to the properties of this component.
This will be needed to restrct access to the modal allowing the user to modify scores.
This commit is contained in:
JP1998 2019-04-09 16:58:56 +02:00
parent ebbff7b01a
commit 2b1d7b084e
1 changed files with 13 additions and 12 deletions

View File

@ -31,16 +31,17 @@ import {
verifyCredentials
} from '../js/api';
class TournamentPage extends React.Component {
class PrivateTournamentPage extends React.Component {
render() {
const { id, description, isPublic, code, ownerUsername, playoffStages } = this.props.tournament;
const { isSignedIn, username } = this.props;
// TODO: Change href-prop of the anchor tag to contain the tournament code
return (
<div className='pb-5'>
<Container>
<EditButton id={id} ownerName={ownerUsername}/>
<EditButton id={id} ownerName={ownerUsername} isSignedIn={isSignedIn} username={username}/>
<p>{description}</p>
<ListGroup>
<ListGroupItem>
@ -59,7 +60,16 @@ class TournamentPage extends React.Component {
}
}
function PrivateEditButton(props) {
function mapStateToTournamentPageProperties(state) {
const { isSignedIn, username } = state.userinfo;
return { isSignedIn, username };
}
const TournamentPage = connect(
mapStateToTournamentPageProperties
)(PrivateTournamentPage);
function EditButton(props) {
const { id, ownerName, isSignedIn, username } = props;
if(isSignedIn && ownerName === username) {
@ -71,15 +81,6 @@ function PrivateEditButton(props) {
}
}
function mapStateToEditButtonProperties(state) {
const { isSignedIn, username } = state.userinfo;
return { isSignedIn, username };
}
const EditButton = connect(
mapStateToEditButtonProperties
)(PrivateEditButton);
function getLevelName(levelNumber) {
const names = ['Finale', 'Halbfinale', 'Viertelfinale', 'Achtelfinale'];
if(levelNumber < names.length){