speed-flowchart-web/src/pages/SpeedFlowchartPage.tsx

62 lines
1.8 KiB
TypeScript

import { Context } from '../data/Context';
import { useContext, useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';
import { SpeedFlowchart, SpeedRound } from '../data/SpeedFlowchart';
import { Card, CardContent, Grid } from '@mui/material';
/**
*
* @return {JSX.Element} speed flowchart page
*/
export default function SpeedFlowchartPage() {
const { competitionId, categoryId } = useParams();
const { api } = useContext(Context);
const [rounds, setRounds] = useState<SpeedRound[]>([]);
useEffect(() => {
if (competitionId === undefined || categoryId === undefined) {
return;
}
api.getCompetitionResults(competitionId, categoryId).then(r => {
const flowchart = new SpeedFlowchart(r);
const rounds = flowchart
._convert()
.filter(round => round.roundName !== undefined && round.pairs.length);
console.log(rounds);
setRounds(rounds);
});
}, []);
return (
<>
<h1>RESULT:</h1>
<Grid container spacing={2}>
{rounds.map((round, roundKey) => (
<Grid key={`flowchart-column-${roundKey}`} item xs={12 / 5}>
<h3>{round.roundName}</h3>
<Grid container spacing={2}>
{round.pairs.map((pair, pairKey) => (
<Grid
key={`flowchart-column-${roundKey}-pair-${pairKey}`}
item
xs={12}
>
<Card>
<CardContent>
A: {pair.laneA?.firstname} {pair.laneA?.lastname}
<br />
B: {pair.laneB?.firstname} {pair.laneB?.lastname}
</CardContent>
</Card>
</Grid>
))}
</Grid>
</Grid>
))}
</Grid>
</>
);
}