Resolve conflicts and style issues

This commit is contained in:
JP1998 2018-12-13 08:49:01 +01:00
parent 4ecd4bd207
commit d307cdb907
2 changed files with 33 additions and 17 deletions

View File

@ -396,6 +396,10 @@ export function updateTeamName(team, successCB, errorCB) {
}); });
} }
export function getState() {
return __store.getState();
}
function rehydrateApplicationState() { function rehydrateApplicationState() {
const persistedState = localStorage.getItem('reduxState') ? const persistedState = localStorage.getItem('reduxState') ?
JSON.parse(localStorage.getItem('reduxState')) : JSON.parse(localStorage.getItem('reduxState')) :

View File

@ -31,31 +31,25 @@ import {
class TournamentPage extends React.Component { class TournamentPage extends React.Component {
static async getInitialProps({query}) {
return {query};
}
componentDidMount() {
verifyCredentials();
}
render() { render() {
const { id, description, isPublic, code, ownerUsername, playoffStages } = this.props.tournament;
// TODO: Change href-prop of the anchor tag to contain the tournament code // TODO: Change href-prop of the anchor tag to contain the tournament code
return ( return (
<div className='pb-5'> <div className='pb-5'>
<Container> <Container>
<a href={'/t/' + props.tournament.id + '/edit'} className='btn btn-outline-secondary'>Turnier bearbeiten</a> <a href={'/t/' + id + '/edit'} className='btn btn-outline-secondary'>Turnier bearbeiten</a>
<p>{props.tournament.description}</p> <p>{description}</p>
<ListGroup> <ListGroup>
<ListGroupItem> <ListGroupItem>
{props.tournament.isPublic ? 'Das Turnier ist öffentlich.' : 'Das Turnier ist privat.'} {isPublic ? 'Das Turnier ist öffentlich.' : 'Das Turnier ist privat.'}
</ListGroupItem> </ListGroupItem>
<ListGroupItem>Turnier-Code: <b>{props.tournament.code}</b></ListGroupItem> <ListGroupItem>Turnier-Code: <b>{code}</b></ListGroupItem>
<ListGroupItem>von <b>{props.tournament.ownerUsername}</b></ListGroupItem> <ListGroupItem>von <b>{ownerUsername}</b></ListGroupItem>
</ListGroup> </ListGroup>
</Container> </Container>
<div className='stages pt-5'> <div className='stages pt-5'>
{props.tournament.playoffStages.map(stage => {playoffStages.map(stage =>
<Stage level={getLevelName(stage.level)} matches={stage.matches} key={stage.level}/>)} <Stage level={getLevelName(stage.level)} matches={stage.matches} key={stage.level}/>)}
</div> </div>
</div> </div>
@ -73,10 +67,12 @@ function getLevelName(levelNumber) {
} }
function TournamentContainer(props) { function TournamentContainer(props) {
if (props.data === null) { const { tournament } = props.data;
if (tournament === null) {
return <Container>null</Container>; return <Container>null</Container>;
} else { } else {
return <Tournament tournament={props.data.tournament}/>; return <TournamentPage tournament={tournament}/>;
} }
} }
@ -355,9 +351,24 @@ function convertMatch(apiMatch) {
} }
class Main extends React.Component { class Main extends React.Component {
static async getInitialProps({query}) {
return {query};
}
constructor(props) { constructor(props) {
super(props); super(props);
this.state = {
tournament : null
};
}
componentDidMount() {
verifyCredentials();
const code = this.props.query.code; const code = this.props.query.code;
getRequest(getState(), '/tournaments/' + code) getRequest(getState(), '/tournaments/' + code)
.then(response => { .then(response => {
this.setState({tournament: convertTournament(response.data)}); this.setState({tournament: convertTournament(response.data)});
@ -365,8 +376,9 @@ class Main extends React.Component {
.catch(() => { /* TODO: Show some kind of error or smth */ }); .catch(() => { /* TODO: Show some kind of error or smth */ });
} }
render() { render() {
const tournamentName = this.state === null ? 'Turnier' : this.state.tournament.name; const tournamentName = this.state.tournament === null ? 'Turnier' : this.state.tournament.name;
return ( return (
<div> <div>
<Head> <Head>