From 2b1d7b084e7ab2452ac37acb9254a02e28b2841a Mon Sep 17 00:00:00 2001 From: JP1998 Date: Tue, 9 Apr 2019 16:58:56 +0200 Subject: [PATCH] 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. --- pages/tournament.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/pages/tournament.js b/pages/tournament.js index 779a0ba..dbff215 100644 --- a/pages/tournament.js +++ b/pages/tournament.js @@ -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 (
- +

{description}

@@ -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){