From cfe57274ddf7ffd148bba7baecb213b4f2195e39 Mon Sep 17 00:00:00 2001 From: Felix Albrigtsen Date: Mon, 28 Mar 2022 15:20:23 +0200 Subject: [PATCH] Coding session - teams, style, appbar --- src/client/src/FrontPage.js | 10 ++- src/client/src/TournamentOverview.js | 21 +++--- src/client/src/TournamentTeams.js | 96 ++++++++++++++++++++++++---- src/client/src/components/appbar.js | 20 +++--- src/client/src/createtournament.js | 59 +++++++++-------- src/client/src/managetournament.js | 72 +++++++++++---------- src/client/src/setupTests.js | 5 -- 7 files changed, 180 insertions(+), 103 deletions(-) delete mode 100644 src/client/src/setupTests.js diff --git a/src/client/src/FrontPage.js b/src/client/src/FrontPage.js index 010bf15..a4f77ce 100644 --- a/src/client/src/FrontPage.js +++ b/src/client/src/FrontPage.js @@ -28,9 +28,7 @@ function CreateButton(props) { function TournamentListItem(props) { return ( - + {props.tournament.description} Start: {props.tournament.startTime.toLocaleString()} End: {props.tournament.endTime.toLocaleString()} - Players todo / {props.tournament.teamLimit} + Players {props.tournament.teamCount} / {props.tournament.teamLimit} - + @@ -106,7 +104,7 @@ function TournamentList() { function Home() { return ( - +
diff --git a/src/client/src/TournamentOverview.js b/src/client/src/TournamentOverview.js index eaec3e9..5092ed7 100644 --- a/src/client/src/TournamentOverview.js +++ b/src/client/src/TournamentOverview.js @@ -2,7 +2,7 @@ import * as React from "react"; import { Link } from "react-router-dom"; import Appbar from './components/appbar'; import { useParams } from 'react-router-dom' -import { Button } from "@mui/material"; +import { Button, Paper, Stack } from "@mui/material"; import "./components/tournamentBracket.css"; function MatchPair(props) { @@ -64,7 +64,6 @@ function Match(props) { let setWinner = curryTeamId => event => { let teamId = curryTeamId; - console.log(teamId); if (!teamId || teamId == null) { showError("No team selected"); return; @@ -157,7 +156,6 @@ function BracketViewer(props) { console.error(data) return; } - console.log(data); let teams = data.data; setTeams(teams); }) @@ -186,13 +184,16 @@ export default function TournamentOverview(props) { return ( <> - - - - - - - + + + + + + + + + + diff --git a/src/client/src/TournamentTeams.js b/src/client/src/TournamentTeams.js index 1f23cb7..a6700d0 100644 --- a/src/client/src/TournamentTeams.js +++ b/src/client/src/TournamentTeams.js @@ -1,15 +1,60 @@ import * as React from "react"; import { BrowserRouter as Router, Link, Route, Routes, useParams } from "react-router-dom"; import Appbar from "./components/appbar"; -import { Button, TextField, Stack, MenuItem, InputLabel, Select, Container, TableContainer, Table, TableBody, TableHead, TableCell, TableRow, Paper, Typography} from "@mui/material"; +import { Button, TextField, Stack, MenuItem, Box, InputLabel, Select, Container, TableContainer, Table, TableBody, TableHead, TableCell, TableRow, Paper, Typography} from "@mui/material"; +import AddCircleIcon from '@mui/icons-material/AddCircle'; + function showError(error) { alert("Something went wrong. \n" + error); console.error(error); } -function TeamList(props) { +function TeamCreator(props) { + function postCreate() { + let teamName = document.getElementById("teamNameInput").value; + if (!teamName) { + showError("Team name is required"); + return; + } + let formData = new FormData(); + formData.append("name", teamName); + let body = new URLSearchParams(formData) + + fetch(process.env.REACT_APP_BACKEND_URL + `/api/tournament/${props.tournamentId}/createTeam`, { + method: "POST", + body: body + }) + .then(res => res.json()) + .then(data => { + if (data.status !== "OK") { + showError(data.data); + return; + } + document.getElementById("teamNameInput").value = ""; + props.onTeamCreated(); + } + ) + } + + return ( + +
+ + {/* */} + +
+
+ ) +} + +function TeamList(props) { return (
@@ -32,7 +77,7 @@ function TeamList(props) { {team.members} - + @@ -75,7 +120,7 @@ function TeamEditor(props) { formData.append("name", document.getElementById("teamNameInput").value); } - if (props.selectedTeamId == -1 || !team) { + if (props.selectedTeamId === -1 || !team) { return (
@@ -86,7 +131,31 @@ function TeamEditor(props) { } function nameInputChanged(event) { - setTeam({...team, name: event.target.value}); + let newTeam = {...team}; + newTeam.name = event.target.value; + setTeam(newTeam); + } + + function saveTeam() { + let formData = new FormData(); + formData.append("name", team.name); + console.log(team); + let body = new URLSearchParams(formData) + fetch(process.env.REACT_APP_BACKEND_URL + `/api/team/${team.id}/edit`, { + method: "POST", + body: body + }) + .then(res => res.json()) + .then(data => { + if (data.status !== "OK") { + showError(data.data); + return; + } + setTeam(data.data); + props.setTeams(props.teams.map(listTeam => listTeam.id === team.id ? team : listTeam)); + props.setSelectedTeamId(-1); + } + ); } return ( @@ -94,8 +163,9 @@ function TeamEditor(props) {

Edit Team:

- + +
@@ -104,10 +174,10 @@ function TeamEditor(props) { export default function TournamentTeams(props) { const [teams, setTeams] = React.useState([]); - const [selectedTeamId, setselectedTeamId] = React.useState(-1); + const [selectedTeamId, setSelectedTeamId] = React.useState(-1); const { tournamentId } = useParams(); - React.useEffect(() => { + function getTeams() { fetch(process.env.REACT_APP_BACKEND_URL + `/api/tournament/${tournamentId}/getTeams`) .then((res) => res.json()) .then((data) => { @@ -118,14 +188,18 @@ export default function TournamentTeams(props) { //setselectedTeamId(teams[0].id); }) .catch((err) => showError(err)); + } + React.useEffect(() => { + getTeams() }, []); return ( <> - +
- - + + +
); diff --git a/src/client/src/components/appbar.js b/src/client/src/components/appbar.js index 7b32e02..e8dcabb 100644 --- a/src/client/src/components/appbar.js +++ b/src/client/src/components/appbar.js @@ -1,32 +1,32 @@ import * as React from "react"; -import { BrowserRouter as Router, Link, Route, Routes } from "react-router-dom"; -import { AppBar, Typography, Toolbar, CssBaseline, Box, IconButton } from "@mui/material" +import { BrowserRouter as Router, Link, Route, Routes, History } from "react-router-dom"; +import { AppBar, Typography, Toolbar, CssBaseline, Box, Button, IconButton } from "@mui/material" import Menu from '@mui/icons-material/Menu' import HomeImage from "./homeimage"; -export default function Appbar() { +export default function Appbar(props) { return ( <> - - - + + Asura Tournaments + {/* */} + +

{props.pageTitle || ""}

+ diff --git a/src/client/src/createtournament.js b/src/client/src/createtournament.js index eebbf71..8dd6de2 100644 --- a/src/client/src/createtournament.js +++ b/src/client/src/createtournament.js @@ -2,7 +2,8 @@ import * as React from "react"; import { BrowserRouter as Router, Link, Route, Routes } from "react-router-dom"; import Appbar from "./components/appbar"; -import { Button, TextField, MenuItem, InputLabel, Select, Container, Slider } from '@mui/material' +import { Button, TextField, Stack, InputLabel, Select, Container, Slider, Paper, Box, Grid } from '@mui/material' +import FileUploadIcon from '@mui/icons-material/FileUpload'; function submitTournament(event) { event.preventDefault(); @@ -82,29 +83,33 @@ function TournamentForm(props) { return ( <>
- - Tournament Name: - - Description: - - - Tournament Image: -
- -
- - Start Time: - + + {/* Tournament Name: */} + + {/* Description: + + + + Edit Image: + + + + + + + + + {/* Start Time: */} + - End Time: - + {/* End Time: */} + Maximum number of teams {/* - + {/* go brrrr */}

-
+
); @@ -149,8 +154,10 @@ function TournamentForm(props) { export default function CreateTournament(props) { return ( <> - + + + ); } diff --git a/src/client/src/managetournament.js b/src/client/src/managetournament.js index 285a408..61f2415 100644 --- a/src/client/src/managetournament.js +++ b/src/client/src/managetournament.js @@ -3,7 +3,8 @@ import { BrowserRouter as Router, Link, Route, Routes } from "react-router-dom"; import { AlertContainer, alert } from "react-custom-alert"; import Appbar from "./components/appbar"; import { useParams } from "react-router-dom"; -import { Button, TextField, MenuItem, InputLabel, Select, Container, Slider} from "@mui/material"; +import { Button, TextField, Grid, Box, Container, Paper, Stack} from "@mui/material"; +import FileUploadIcon from '@mui/icons-material/FileUpload'; let submitChanges = curryTournamentId => event => { event.preventDefault(); @@ -71,7 +72,6 @@ function ManageTournament(props) { let [tournamentInfo, setTournamentInfo] = React.useState([]); React.useEffect(() => { - console.log(props.tournamentId); fetch( process.env.REACT_APP_BACKEND_URL + `/api/tournament/${props.tournamentId}` @@ -93,40 +93,40 @@ function ManageTournament(props) { return ( <> -
- - Edit name: - - Edit description: - - - Edit image: -
- -
- - Edit Start Time: - - - Edit End Time: - - + + +
+ + + + {/* Edit Start Time: */} + + {/* Edit End Time: */} + + - - + + + ); } @@ -172,11 +172,13 @@ export default function TournamentManager(props) { const { tournamentId } = useParams(); return ( <> - + + + ); } diff --git a/src/client/src/setupTests.js b/src/client/src/setupTests.js deleted file mode 100644 index 8f2609b..0000000 --- a/src/client/src/setupTests.js +++ /dev/null @@ -1,5 +0,0 @@ -// jest-dom adds custom jest matchers for asserting on DOM nodes. -// allows you to do things like: -// expect(element).toHaveTextContent(/react/i) -// learn more: https://github.com/testing-library/jest-dom -import '@testing-library/jest-dom';