From 2b1d7b084e7ab2452ac37acb9254a02e28b2841a Mon Sep 17 00:00:00 2001 From: JP1998 Date: Tue, 9 Apr 2019 16:58:56 +0200 Subject: [PATCH 1/3] 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){ From 6035da058ed052262bf668efb325049bdf27c5d9 Mon Sep 17 00:00:00 2001 From: JP1998 Date: Tue, 9 Apr 2019 17:00:49 +0200 Subject: [PATCH 2/3] Restrict access to the modal for users that are not the owner of the tournament --- pages/tournament.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pages/tournament.js b/pages/tournament.js index dbff215..6874c08 100644 --- a/pages/tournament.js +++ b/pages/tournament.js @@ -53,7 +53,7 @@ class PrivateTournamentPage extends React.Component {
{playoffStages.map(stage => - )} + )}
); @@ -113,7 +113,11 @@ class Match extends React.Component { } toggleModal() { - this.setState({modal: !this.state.modal}); + const { isSignedIn, isOwner } = this.props; + + if(isSignedIn && isOwner) { + this.setState({modal: !this.state.modal}); + } } render() { From 45136aa1d6bb92be89c384fec9fad7d36682f470 Mon Sep 17 00:00:00 2001 From: JP1998 Date: Tue, 9 Apr 2019 17:03:04 +0200 Subject: [PATCH 3/3] Fix a bug which crashes the site when there is no internet connection In case there is no internet connection axios will not return a response object with the error after a request. Since we still tried to access said object the website crashed when there was no internet connection. --- pages/tournament.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pages/tournament.js b/pages/tournament.js index 6874c08..cae6a93 100644 --- a/pages/tournament.js +++ b/pages/tournament.js @@ -392,7 +392,11 @@ class Main extends React.Component { this.setState({ status : response.status, tournament : convertTournament(response.data)}); }) .catch((err) => { - this.setState({ status : err.response.status }); + if(err.response) { + this.setState({ status : err.response.status }); + } else { + this.setState({ status : -1 }); + } }); }