import Head from 'next/head';
import React from 'react';
import {ErrorPageComponent} from '../js/components/ErrorComponents';
import 'bootstrap/dist/css/bootstrap.min.css';
import '../static/css/everypage.css';
import '../static/css/tournament-fullscreen.css';
import {getTournamentMatches, getTournamentMeta} from '../js/redux/tournamentApi';
import {Navbar, NavbarBrand, NavItem} from 'reactstrap';
function FullscreenPage(props) {
return (
{JSON.stringify(props.tournamentMeta)}
);
}
function Matches(props) {
return (
{props.matches.map(match => )}
);
}
function Match(props) {
return {JSON.stringify(props.match)}
;
}
function FullscreenPageHeader(props) {
return (
{props.levelName}
{props.title}
Turnier-Code: {props.code}
);
}
class Main extends React.Component {
static async getInitialProps({query}) {
return {query};
}
constructor(props) {
super(props);
this.state = {
tournamentMeta: null, matches: []
};
this.onTournamentRequestSuccess = this.onTournamentRequestSuccess.bind(this);
this.onTournamentRequestError = this.onTournamentRequestError.bind(this);
this.onTournamentMatchesRequestSuccess = this.onTournamentMatchesRequestSuccess.bind(this);
this.onTournamentMatchesRequestError = this.onTournamentMatchesRequestError.bind(this);
this.updateMatches = this.updateMatches.bind(this);
}
componentDidMount() {
const tournamentId = this.props.query.code;
getTournamentMeta(tournamentId, this.onTournamentRequestSuccess, this.onTournamentRequestError);
this.updateMatches();
const intervalId = setInterval(this.updateMatches, 3000);
this.setState({intervalId: intervalId});
}
componentWillUnmount() {
clearInterval(this.state.intervalId);
}
updateMatches() {
const tournamentId = this.props.query.code;
getTournamentMatches(tournamentId, this.onTournamentMatchesRequestSuccess,
this.onTournamentMatchesRequestError);
}
onTournamentRequestSuccess(requestStatus, tournament) {
this.setState({metaStatus: requestStatus, tournamentMeta: tournament});
}
onTournamentRequestError(error) {
if (error.response) {
this.setState({metaStatus: error.response.status});
} else {
this.setState({metaStatus: -1});
}
}
onTournamentMatchesRequestSuccess(requestStatus, matches) {
this.setState({matchesStatus: requestStatus, matches: matches});
}
onTournamentMatchesRequestError(error) {
if (error.response) {
this.setState({matchesStatus: error.response.status});
} else {
this.setState({matchesStatus: -1});
}
}
render() {
const {metaStatus, tournamentMeta, matches} = this.state;
if (metaStatus === 200) {
return (
{tournamentMeta.name}: turnie.re
);
} else {
return ;
}
}
}
export default Main;