import { Context } from '../data/Context'; import { useContext, useEffect, useState } from 'react'; import { useParams } from 'react-router-dom'; import { convertResultsToSpeedFlowchartResult, SpeedFlowchartResult, SpeedRoundPair, } from '../data/SpeedFlowchart'; import { Card, CardContent, Grid, Skeleton, Typography } from '@mui/material'; import { theme } from '../utils/Theme'; import { QRCode } from 'react-qrcode-logo'; import { bgcolor } from '@mui/system'; import '../css/SpeedFlowchartPage.css'; interface SpeedRoundPairDummy extends SpeedRoundPair { dummy: boolean; } /** * * @return {JSX.Element} speed flowchart page */ export default function SpeedFlowchartPage() { const { competitionId, categoryId } = useParams(); const { api, setTitle, setContainerMaxWidth } = useContext(Context); const [loading, setLoading] = useState(true); const [flowchartResult, setFlowchartResult] = useState(); useEffect(() => { setTitle(''); setContainerMaxWidth(false); loadData(); const interval = setInterval(loadData, 2000); return () => clearInterval(interval); }, []); const loadData = () => { if (competitionId === undefined || categoryId === undefined) { setLoading(false); return; } api.getCompetitionResults(competitionId, categoryId).then(r => { setTitle( `${r.comp_name} - ${ r.categorys.filter(cat => cat.GrpId === categoryId)[0]?.name ?? '' }`, ); setLoading(false); const flowchartResult = convertResultsToSpeedFlowchartResult(r); const l = flowchartResult.rounds.length; const dummy: SpeedRoundPairDummy = { dummy: true }; flowchartResult.rounds[l - 2].pairs = [ dummy, ...flowchartResult.rounds[l - 1].pairs, ...flowchartResult.rounds[l - 2].pairs, ]; flowchartResult.rounds[l - 2].roundName = `${ flowchartResult.rounds[l - 1].roundName } / ${flowchartResult.rounds[l - 2].roundName}`; flowchartResult.rounds.pop(); setFlowchartResult(flowchartResult); }); }; return ( <> {flowchartResult?.rounds.map((round, roundKey) => ( {round.roundName} {round.pairs.length === 2 && (
)} {round.pairs.map((pair, pairKey) => ( A: {pair.laneA?.participant.firstName}{' '} {pair.laneA?.participant.lastName}:{' '} {pair.laneA?.result?.result} B: {pair.laneB?.participant.firstName}{' '} {pair.laneB?.participant.lastName}:{' '} {pair.laneB?.result?.result} ))}
))} {flowchartResult === undefined && !loading && ( This competition or category does not have a speed tree! )} {loading && new Array(5).fill(0).map((_, i) => ( ))}
); }