import { Context } from '../data/Context'; import { useContext, useEffect, useState } from 'react'; import { useParams } from 'react-router-dom'; import { convertResultsToSpeedFlowchartResult, SpeedFlowchartResult, } from '../data/SpeedFlowchart'; import { Card, CardContent, Grid, Skeleton, Typography } from '@mui/material'; /** * * @return {JSX.Element} speed flowchart page */ export default function SpeedFlowchartPage() { const { competitionId, categoryId } = useParams(); const { api, setTitle } = useContext(Context); const [loading, setLoading] = useState(true); const [flowchartResult, setFlowchartResult] = useState(); useEffect(() => { if (competitionId === undefined || categoryId === undefined) { return; } setTitle(''); api.getCompetitionResults(competitionId, categoryId).then(r => { setTitle( `${r.comp_name} - ${ r.categorys.filter(cat => cat.GrpId === categoryId)[0]?.name ?? '' }`, ); setLoading(false); console.log('loading false'); const flowchartResult = convertResultsToSpeedFlowchartResult(r); console.log(flowchartResult); setFlowchartResult(flowchartResult); }); }, []); return ( <> {flowchartResult?.rounds.map((round, roundKey) => (

{round.roundName}

{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) => ( ))}
); }