diff --git a/src/client/src/TournamentHistory.js b/src/client/src/TournamentHistory.js new file mode 100644 index 0000000..e874523 --- /dev/null +++ b/src/client/src/TournamentHistory.js @@ -0,0 +1,122 @@ +import * as React from "react"; +import { BrowserRouter as Router, Link, Route, Routes } from "react-router-dom"; +import { Button, Container, Typography, Box, Stack, Card, CardContent, CardMedia, Paper, Grid, Icon } from "@mui/material"; +import AddCircleIcon from '@mui/icons-material/AddCircle'; +import KeyboardDoubleArrowDownIcon from '@mui/icons-material/KeyboardDoubleArrowDown'; +import KeyboardDoubleArrowUpIcon from '@mui/icons-material/KeyboardDoubleArrowUp'; +import Appbar from './components/AsuraBar'; + +function shorten(description, maxLength) { + if (description.length > maxLength) { + return description.substring(0, maxLength) + "..."; + } + return description; + } + + function TournamentListItem(props) { + const [longDescription, setLongDescription] = React.useState(false); + const maxLength = 200; + function toggleDescription() { + setLongDescription(!longDescription); + } + function Description() { + if (longDescription) { + return( + {props.tournament.description} + + ) + } else if (props.tournament.description.length < maxLength) { + return {props.tournament.description} + } else { + return + {shorten(props.tournament.description, maxLength)} + + ; + } + } + return ( + + + + + {props.tournament.name} + + + Start: {props.tournament.startTime.toLocaleString()} + End: {props.tournament.endTime.toLocaleString()} + + + Players {props.tournament.teamCount} / {props.tournament.teamLimit} + + + + + + + + + + + + + + + ); + } + + function TournamentList() { + let [tournamentList, setTournamentList] = React.useState([]); + + React.useEffect(() => { + fetch(process.env.REACT_APP_API_URL + `/tournament/getTournaments`) + .then(res => res.json()) + .then(data => { + if (data.status !== "OK") { + console.error(data); + return; + } + + let tournamenthistory = [] + let today = new Date() + let tournaments = Object.values(data.data); + for (let i = 0; i < tournaments.length; i++) { + tournaments[i].startTime = new Date(tournaments[i].startTime); + tournaments[i].endTime = new Date(tournaments[i].endTime); + if(today - tournaments[i].endTime >= 24*60*60*1000) { + tournamenthistory.push(tournaments[i]) + } + } + + setTournamentList(tournamenthistory); + }) + .catch((err) => console.log(err.message)); + }, []); + + return <> + + {tournamentList && tournamentList.map((tournamentObject) => )} + + + ; + } + +export default function TournamentHistory() { + return ( + <> + + + + Past Tournaments + + + + + ); +} \ No newline at end of file