Merge branch 'client-kristofferTournament' into 'client'
Merging brackets into client See merge request felixalb/dcst1008-2022-group1!1
This commit is contained in:
commit
ffe708ae47
|
@ -3,72 +3,53 @@ import { Link } from "react-router-dom";
|
|||
import Appbar from './components/AsuraBar';
|
||||
import TournamentBar from "./components/TournamentBar";
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { Button, Paper, Stack, CircularProgress, Box } from "@mui/material";
|
||||
import { Button, IconButton, Paper, Stack, CircularProgress, Box, Grid, Typography, Container } from "@mui/material";
|
||||
import "./components/tournamentBracket.css";
|
||||
import EmojiEventsIcon from '@mui/icons-material/EmojiEvents';
|
||||
import DoDisturbIcon from '@mui/icons-material/DoDisturb';
|
||||
import BackspaceIcon from '@mui/icons-material/Backspace';
|
||||
import AddCircleIcon from '@mui/icons-material/AddCircle';
|
||||
|
||||
function MatchPair(props) {
|
||||
let match1 = <Match teams={props.teams} match={props.matches[0]} key={0} />;
|
||||
let match2 = <Match teams={props.teams} match={props.matches[1]} key={1} />;
|
||||
|
||||
return <div className="winners">
|
||||
<div className="matchups">
|
||||
{match1}
|
||||
{match2}
|
||||
</div>
|
||||
<div className="connector">
|
||||
<div className="merger"></div>
|
||||
<div className="line"></div>
|
||||
</div>
|
||||
</div>
|
||||
function showError(error) {
|
||||
alert("Something went wrong. \n" + error);
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
function TournamentTier(props) {
|
||||
// One round/tier of the tournament, as used by BracketViewer
|
||||
function TournamentTier(props){
|
||||
let roundTypes = ["finals", "semifinals", "quarterfinals", "eighthfinals", "sixteenthfinals", "thirtysecondfinals"];
|
||||
|
||||
if (props.tier === 0) {
|
||||
// The final, just a single match without the bracket lines
|
||||
return (
|
||||
<section className="round finals"><div className="winners">
|
||||
<div className="matchups">
|
||||
<Match teams={props.teams} match={props.matches[0]} key={0} />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
} else {
|
||||
// The rest of the rounds/tiers, divide into pairs of two matches
|
||||
let matchPairCount = props.matches.length / 2;
|
||||
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} />);
|
||||
let matches = [];
|
||||
for (let i = 0; i < props.matches.length; i++) {
|
||||
matches.push(<Match teams={props.teams} match={props.matches[i]} key={i} />);
|
||||
}
|
||||
|
||||
return (
|
||||
<section className={`round ${roundTypes[props.tier]}`}>
|
||||
{matchPairs}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
return(
|
||||
<ul className={`round ${roundTypes[props.tier]}`}>
|
||||
<li className="spacer"> </li>
|
||||
{matches}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
|
||||
function Match(props) {
|
||||
// A single match object, as used by MatchPair and TournamentTier
|
||||
function Match(props){
|
||||
let team1Name = "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;
|
||||
}
|
||||
if (props.match.team2Id !== null) {
|
||||
if(props.match.team2Id !== null) {
|
||||
team2Name = props.teams.find(team => team.id === props.match.team2Id).name;
|
||||
}
|
||||
|
||||
let setWinner = curryTeamId => event => {
|
||||
let teamId = curryTeamId;
|
||||
console.log(teamId)
|
||||
if (!teamId || teamId == null) {
|
||||
showError("No team selected");
|
||||
return;
|
||||
}
|
||||
// if(props.match.winnerId === teamId){
|
||||
// showError("Team already won");
|
||||
// return;
|
||||
// }
|
||||
let formData = new FormData();
|
||||
formData.append("winnerId",teamId);
|
||||
let body = new URLSearchParams(formData);
|
||||
|
@ -89,27 +70,52 @@ function Match(props) {
|
|||
}
|
||||
|
||||
return (
|
||||
<div className="matchup">
|
||||
<div className="participants">
|
||||
<>
|
||||
{/* Team 1 (Winner-status?) (Team name) */}
|
||||
<div onClick={setWinner(props.match.team1Id)} className={`participant ${props.match.winnerId && (props.match.team1Id === props.match.winnerId) ? "winner" : ""}`}>
|
||||
<span>{team1Name}</span>
|
||||
</div>
|
||||
<li className={`game game-top ${props.match.winnerId && (props.match.team1Id === props.match.winnerId) ? "winner" : "loser"}`}>
|
||||
<Stack direction={"row"}>
|
||||
<Typography className={`teamName`} align={'center'} sx={{fontSize:'1.5rem'}}>
|
||||
{team1Name}
|
||||
</Typography>
|
||||
{ props.match.winnerId && (props.match.team1Id === props.match.winnerId) &&
|
||||
<IconButton color="error" aria-label="remmove winner" component="span"><BackspaceIcon /></IconButton>
|
||||
}
|
||||
{ props.match.team1Id !== null &&
|
||||
<IconButton onClick={setWinner(props.match.team1Id)} color="success" aria-label="select winner" component="span"><AddCircleIcon /></IconButton>
|
||||
}
|
||||
{/* { props.match.winnerId && (props.match.team1Id === props.match.winnerId) &&
|
||||
<EmojiEventsIcon alt="A trohpy" color="gold" />
|
||||
} */}
|
||||
</Stack>
|
||||
</li>
|
||||
<li className="game game-spacer"> </li>
|
||||
{/* Team 2 (Winner-status?) (Team name) */}
|
||||
<div onClick={setWinner(props.match.team2Id)} className={`participant ${props.match.winnerId && (props.match.team2Id === props.match.winnerId) ? "winner" : ""}`}>
|
||||
<span>{team2Name}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<li className={`game game-bottom ${props.match.winnerId && (props.match.team2Id === props.match.winnerId) ? "winner" : "loser"}`}>
|
||||
<Stack direction={"row"} sx={{alignItems:'center'}}>
|
||||
<Typography className={`teamName`} sx={{fontSize:'1.5rem'}}>
|
||||
{team2Name}
|
||||
</Typography>
|
||||
{ props.match.winnerId && (props.match.team2Id === props.match.winnerId) &&
|
||||
<IconButton color="error" aria-label="remmove winner" component="span"><BackspaceIcon /></IconButton>
|
||||
}
|
||||
{ props.match.team2Id !== null &&
|
||||
<IconButton onClick={setWinner(props.match.team2Id)} color="success" aria-label="select winner" component="span"><AddCircleIcon /></IconButton>
|
||||
}
|
||||
{/* { props.match.winnerId && (props.match.team2Id === props.match.winnerId) &&
|
||||
<EmojiEventsIcon alt="A trohpy" color="gold" />
|
||||
} */}
|
||||
</Stack>
|
||||
</li>
|
||||
<li className="spacer"> </li>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function BracketViewer(props) {
|
||||
function BracketViewer(props){
|
||||
const [tournament, setTournament] = React.useState(null);
|
||||
const [matches, setMatches] = React.useState(null);
|
||||
const [teams, setTeams] = React.useState(null);
|
||||
|
||||
// One fetch statement for each of the three state variables
|
||||
React.useEffect(() => {
|
||||
fetch(process.env.REACT_APP_API_URL + `/tournament/${props.tournamentId}`)
|
||||
.then(res => res.json())
|
||||
|
@ -162,7 +168,6 @@ function BracketViewer(props) {
|
|||
})
|
||||
.catch(err => showError(err));
|
||||
}, []);
|
||||
|
||||
return (
|
||||
(matches && teams) ?
|
||||
// <div sx={{width: "100vw", height: "80vh", overflow: "scroll"}} className="bracket">
|
||||
|
|
|
@ -1,142 +1,69 @@
|
|||
/* https://codepen.io/semibran/pen/VjmPJd */
|
||||
html {
|
||||
font-size: 1rem;
|
||||
}
|
||||
/*
|
||||
* Flex Layout Specifics
|
||||
*/
|
||||
.bracket{
|
||||
display:flex;
|
||||
flex-direction:row;
|
||||
justify-content: center;
|
||||
}
|
||||
.round{
|
||||
display:flex;
|
||||
flex-direction:column;
|
||||
justify-content:center;
|
||||
width:200px;
|
||||
list-style:none;
|
||||
padding:0;
|
||||
font-size: 2rem;
|
||||
}
|
||||
.round .spacer{ flex-grow:1;}
|
||||
.round .spacer:first-child,
|
||||
.round .spacer:last-child{ flex-grow:.5; }
|
||||
.round .game-spacer{
|
||||
flex-grow:1;
|
||||
}
|
||||
|
||||
/*
|
||||
* General Styles
|
||||
*/
|
||||
/* body{
|
||||
font-family:sans-serif;
|
||||
font-size:medium;
|
||||
padding:10px;
|
||||
line-height:1.4em;
|
||||
} */
|
||||
|
||||
.bracket {
|
||||
display: inline-block;
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.bracket .round {
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.bracket .round .winners>div {
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.bracket .round .winners>div.matchups .matchup:last-child {
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.bracket .round .winners>div.matchups .matchup .participants {
|
||||
border-radius: 0.25rem;
|
||||
overflow: hidden;
|
||||
border: 1px solid gray;
|
||||
}
|
||||
|
||||
.bracket .round .winners>div.matchups .matchup .participants .participant {
|
||||
box-sizing: border-box;
|
||||
color: #404040;
|
||||
border-left: 0.25rem solid #858585;
|
||||
background: white;
|
||||
width: 14rem;
|
||||
height: 3rem;
|
||||
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
|
||||
.bracket .round .winners>div.matchups .matchup .participants .participant.winner {
|
||||
color: green;
|
||||
border-color: #60c645;
|
||||
}
|
||||
|
||||
.bracket .round .winners>div.matchups .matchup .participants .participant.loser {
|
||||
color: #dc563f;
|
||||
border-color: #dc563f;
|
||||
}
|
||||
|
||||
.bracket .round .winners>div.matchups .matchup .participants .participant:not(:last-child) {
|
||||
border-bottom: thin solid #f0f2f2;
|
||||
}
|
||||
|
||||
.bracket .round .winners>div.matchups .matchup .participants .participant span {
|
||||
margin: 0 1.25rem;
|
||||
line-height: 3;
|
||||
font-size: 1rem;
|
||||
font-family: "Roboto Slab";
|
||||
overflow: ellipsis;
|
||||
}
|
||||
|
||||
.bracket .round .winners>div.connector.filled .line,
|
||||
.bracket .round .winners>div.connector.filled.bottom .merger:after,
|
||||
.bracket .round .winners>div.connector.filled.top .merger:before {
|
||||
border-color: #60c645;
|
||||
}
|
||||
|
||||
.bracket .round .winners>div.connector .line,
|
||||
.bracket .round .winners>div.connector .merger {
|
||||
box-sizing: border-box;
|
||||
width: 2rem;
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.bracket .round .winners>div.connector .line {
|
||||
border-bottom: thin solid #c0c0c8;
|
||||
height: 4rem;
|
||||
}
|
||||
|
||||
.bracket .round .winners>div.connector .merger {
|
||||
position: relative;
|
||||
height: 8rem;
|
||||
}
|
||||
|
||||
.bracket .round .winners>div.connector .merger:before,
|
||||
.bracket .round .winners>div.connector .merger:after {
|
||||
content: "";
|
||||
display: block;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
height: 50%;
|
||||
border: 0 solid;
|
||||
border-color: #c0c0c8;
|
||||
}
|
||||
|
||||
.bracket .round .winners>div.connector .merger:before {
|
||||
border-right-width: thin;
|
||||
border-top-width: thin;
|
||||
}
|
||||
|
||||
.bracket .round .winners>div.connector .merger:after {
|
||||
border-right-width: thin;
|
||||
border-bottom-width: thin;
|
||||
}
|
||||
|
||||
.bracket .round.quarterfinals .winners:not(:last-child) {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.bracket .round.quarterfinals .winners .matchups .matchup:not(:last-child) {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.bracket .round.semifinals .winners .matchups .matchup:not(:last-child) {
|
||||
margin-bottom: 10rem;
|
||||
}
|
||||
|
||||
.bracket .round.semifinals .winners .connector .merger {
|
||||
height: 16rem;
|
||||
}
|
||||
|
||||
.bracket .round.semifinals .winners .connector .line {
|
||||
height: 8rem;
|
||||
}
|
||||
|
||||
.bracket .round.finals .winners .connector .merger {
|
||||
height: 3rem;
|
||||
}
|
||||
|
||||
.bracket .round.finals .winners .connector .line {
|
||||
height: 1.5rem;
|
||||
}
|
||||
|
||||
.participant:hover {
|
||||
background: lightgreen!important;
|
||||
}
|
||||
.teamName{
|
||||
max-width: 7.5vw;
|
||||
overflow: hidden;
|
||||
word-wrap: none;
|
||||
}
|
||||
|
||||
li.game{
|
||||
padding-left:20px;
|
||||
}
|
||||
.winnerTrophy{
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.teamName.winner{
|
||||
font-weight:bold;
|
||||
}
|
||||
li.game.winner > div.winnerTrophy{
|
||||
visibility: visible;
|
||||
}
|
||||
/* li.game .winnerTrophy{
|
||||
float:right;
|
||||
margin-right:5px;
|
||||
} */
|
||||
|
||||
li.game-top{ border-bottom:1px solid #aaa; }
|
||||
|
||||
li.game-spacer{
|
||||
border-right:1px solid #aaa;
|
||||
min-height:10vh;
|
||||
}
|
||||
|
||||
li.game-bottom{
|
||||
border-top:1px solid #aaa;
|
||||
}
|
||||
|
Loading…
Reference in New Issue