Vizualisation done, now to fix bugs
This commit is contained in:
parent
340beb9aa4
commit
24dcdd9c0a
|
@ -8,62 +8,40 @@ import "./components/tournamentBracket.css";
|
||||||
import EmojiEventsIcon from '@mui/icons-material/EmojiEvents';
|
import EmojiEventsIcon from '@mui/icons-material/EmojiEvents';
|
||||||
import DoDisturbIcon from '@mui/icons-material/DoDisturb';
|
import DoDisturbIcon from '@mui/icons-material/DoDisturb';
|
||||||
|
|
||||||
function MatchPair(props) {
|
function showError(error) {
|
||||||
let team1 = <Match teams={props.teams} match={props.matches[0]} key={0} />;
|
alert("Something went wrong. \n" + error);
|
||||||
let team2 = <Match teams={props.teams} match={props.matches[1]} key={1} />;
|
console.error(error);
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<li className="game game-top">Test 1</li>
|
|
||||||
<li className="game game-spacer"> </li>
|
|
||||||
<li className="game game-bottom">Test 2</li>
|
|
||||||
<li className="spacer"> </li>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function TournamentTier(props) {
|
function TournamentTier(props){
|
||||||
// One round/tier of the tournament, as used by BracketViewer
|
|
||||||
let roundTypes = ["finals", "semifinals", "quarterfinals", "eighthfinals", "sixteenthfinals", "thirtysecondfinals"];
|
let roundTypes = ["finals", "semifinals", "quarterfinals", "eighthfinals", "sixteenthfinals", "thirtysecondfinals"];
|
||||||
|
let matches = [];
|
||||||
// if (props.tier === 0) {
|
for (let i = 0; i < props.matches.length; i++) {
|
||||||
// // The final, just a single match without the bracket lines
|
matches.push(<Match teams={props.teams} match={props.matches[i]} key={i} />);
|
||||||
// return (
|
|
||||||
// <ul className="round finals">
|
|
||||||
// <li className="spacer"> </li>
|
|
||||||
// <Match teams={props.teams} match={props.matches[0]} key={0} />
|
|
||||||
// </ul>
|
|
||||||
// );
|
|
||||||
// } else {
|
|
||||||
// The rest of the rounds/tiers, divide into pairs of two matches
|
|
||||||
let matchPairCount = props.matches.length;
|
|
||||||
let matchPairs = [];
|
|
||||||
for (let i = 0; i < matchPairCount; i++) {
|
|
||||||
matchPairs.push(<MatchPair teams={props.teams} matches={props.matches.slice(i * 2, i * 2 + 2)} key={i} />);
|
|
||||||
}
|
}
|
||||||
|
return(
|
||||||
return (
|
|
||||||
<ul className={`round ${roundTypes[props.tier]}`}>
|
<ul className={`round ${roundTypes[props.tier]}`}>
|
||||||
<li className="spacer"> </li>
|
<li className="spacer"> </li>
|
||||||
{matchPairs}
|
{matches}
|
||||||
</ul>
|
</ul>
|
||||||
);
|
)
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Match(props) {
|
|
||||||
// A single match object, as used by MatchPair and TournamentTier
|
|
||||||
|
function Match(props){
|
||||||
let team1Name = "TBA";
|
let team1Name = "TBA";
|
||||||
let team2Name = "TBA";
|
let team2Name = "TBA";
|
||||||
if (props.match.team1Id !== null) {
|
if(props.match.team1Id !== null) {
|
||||||
team1Name = props.teams.find(team => team.id === props.match.team1Id).name;
|
team1Name = props.teams.find(team => team.id === props.match.team1Id).name;
|
||||||
}
|
}
|
||||||
if (props.match.team2Id !== null) {
|
if(props.match.team2Id !== null) {
|
||||||
team2Name = props.teams.find(team => team.id === props.match.team2Id).name;
|
team2Name = props.teams.find(team => team.id === props.match.team2Id).name;
|
||||||
}
|
}
|
||||||
|
|
||||||
let setWinner = curryTeamId => event => {
|
let setWinner = curryTeamId => event => {
|
||||||
let teamId = curryTeamId;
|
let teamId = curryTeamId;
|
||||||
|
console.log(teamId)
|
||||||
if (!teamId || teamId == null) {
|
if (!teamId || teamId == null) {
|
||||||
showError("No team selected");
|
showError("No team selected");
|
||||||
return;
|
return;
|
||||||
|
@ -90,25 +68,26 @@ function Match(props) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Team 1 (Winner-status?) (Team name) */}
|
{/* Team 1 (Winner-status?) (Team name) */}
|
||||||
<li onClick={setWinner(props.match.team1Id)} className={`game game-top ${props.match.winnerId && (props.match.team1Id === props.match.winnerId) ? "winner" : ""}`}>
|
<li id={props.match.team1Id} onClick={setWinner(props.match.team1Id)} className={`game game-top ${props.match.winnerId && (props.match.team1Id === props.match.winnerId) ? "winner" : ""}`}>
|
||||||
{team1Name}
|
{team1Name} <span><EmojiEventsIcon alt="A trohpy"/></span>
|
||||||
</li>
|
</li>
|
||||||
<li className="game game-spacer"> </li>
|
<li className="game game-spacer"> </li>
|
||||||
{/* Team 2 (Winner-status?) (Team name) */}
|
{/* Team 2 (Winner-status?) (Team name) */}
|
||||||
<li onClick={setWinner(props.match.team2Id)} className={`game game-bottom ${props.match.winnerId && (props.match.team2Id === props.match.winnerId) ? "winner" : ""}`}>
|
<li id={props.match.team2Id} onClick={setWinner(props.match.team2Id)} className={`game game-bottom ${props.match.winnerId && (props.match.team2Id === props.match.winnerId) ? "winner" : ""}`}>
|
||||||
{team2Name}
|
{team2Name} <span><EmojiEventsIcon alt="A trohpy"/></span>
|
||||||
</li>
|
</li>
|
||||||
<li className="spacer"> </li>
|
<li className="spacer"> </li>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function BracketViewer(props) {
|
function BracketViewer(props){
|
||||||
const [tournament, setTournament] = React.useState(null);
|
const [tournament, setTournament] = React.useState(null);
|
||||||
const [matches, setMatches] = React.useState(null);
|
const [matches, setMatches] = React.useState(null);
|
||||||
const [teams, setTeams] = React.useState(null);
|
const [teams, setTeams] = React.useState(null);
|
||||||
|
|
||||||
// One fetch statement for each of the three state variables
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
fetch(process.env.REACT_APP_API_URL + `/tournament/${props.tournamentId}`)
|
fetch(process.env.REACT_APP_API_URL + `/tournament/${props.tournamentId}`)
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
|
@ -161,23 +140,17 @@ function BracketViewer(props) {
|
||||||
})
|
})
|
||||||
.catch(err => showError(err));
|
.catch(err => showError(err));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
(matches && teams) ?
|
(matches && teams) ?
|
||||||
// <div sx={{width: "100vw", height: "80vh", overflow: "scroll"}} className="bracket">
|
// <div sx={{width: "100vw", height: "80vh", overflow: "scroll"}} className="bracket">
|
||||||
<div className="bracket">
|
<div className="bracket">
|
||||||
{matches.map(tier => {
|
{matches.map(tier => {
|
||||||
let tierNum = tier[0].tier;
|
let tierNum = tier[0].tier;
|
||||||
return <TournamentTier key={tierNum} tier={tierNum} matches={tier} teams={teams} />
|
return <TournamentTier key={tierNum} tier={tierNum} matches={tier} teams={teams} />
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
: <Box sx={{display:'flex', justifyContent:'center', alignItems:'center', position:'relative', marginTop:'5%'}}><CircularProgress size={"20vw"}/></Box>
|
: <Box sx={{display:'flex', justifyContent:'center', alignItems:'center', position:'relative', marginTop:'5%'}}><CircularProgress size={"20vw"}/></Box>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
function showError(error) {
|
|
||||||
alert("Something went wrong. \n" + error);
|
|
||||||
console.error(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TournamentOverview(props) {
|
export default function TournamentOverview(props) {
|
||||||
|
|
|
@ -35,10 +35,16 @@
|
||||||
li.game{
|
li.game{
|
||||||
padding-left:20px;
|
padding-left:20px;
|
||||||
}
|
}
|
||||||
|
li.game > span{
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
li.game.winner{
|
li.game.winner{
|
||||||
font-weight:bold;
|
font-weight:bold;
|
||||||
}
|
}
|
||||||
|
li.game.winner > span{
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
li.game span{
|
li.game span{
|
||||||
float:right;
|
float:right;
|
||||||
margin-right:5px;
|
margin-right:5px;
|
||||||
|
|
Loading…
Reference in New Issue