import styled from '@emotion/styled'; import { Box, CircularProgress, Collapse, IconButton, ListItemButton, Tooltip, Typography, } from '@mui/material'; import { KeyboardArrowDown, KeyboardArrowRight, KeyboardArrowUp, Refresh, } from '@mui/icons-material'; import { useState } from 'react'; import { Event, NameWithHighlight, Phase, PhaseGroup, SelectedEvent, SelectedPhase, SelectedPhaseGroup, Set, State, Tournament, } from '../common/types'; import SetViewInner from './SetView'; import filterSets from './filterSets'; import TiebreakerDialog from './TiebreakerDialog'; const Block = styled.div` padding-left: 8px; `; const Name = styled.div` overflow-x: hidden; text-overflow: ellipsis; white-space: nowrap; `; function SetView({ set, entrant1Names, entrant2Names, vlerkMode, selectSet, }: { set: Set; entrant1Names: NameWithHighlight[]; entrant2Names: NameWithHighlight[]; vlerkMode: boolean; selectSet: () => Promise; }) { return ( { selectSet(); }} > ); } function PhaseGroupView({ phaseGroup, initiallyOpen, ancestorsOpen, searchSubstr, vlerkMode, getPhaseGroup, selectSet, }: { phaseGroup: PhaseGroup; initiallyOpen: boolean; ancestorsOpen: boolean; searchSubstr: string; vlerkMode: boolean; getPhaseGroup: (id: number) => Promise; selectSet: (set: Set) => Promise; }) { const [getting, setGetting] = useState(false); const [completedOpen, setCompletedOpen] = useState(vlerkMode); const [open, setOpen] = useState(initiallyOpen); const get = async () => { setGetting(true); await getPhaseGroup(phaseGroup.id); setGetting(false); }; const pendingSetsToShow = filterSets( phaseGroup.sets.pendingSets, searchSubstr, ); const completedSetsToShow = filterSets( phaseGroup.sets.completedSets, searchSubstr, ); return ( (!searchSubstr || pendingSetsToShow.length > 0 || completedSetsToShow.length > 0) && ( <> { if ( !open && phaseGroup.sets.pendingSets.length === 0 && phaseGroup.sets.completedSets.length === 0 ) { get(); } setOpen((oldOpen) => !oldOpen); }} sx={{ typography: 'caption' }} > {open ? : } {phaseGroup.name} {'\u00A0'}({phaseGroup.id}) { event.stopPropagation(); get(); }} size="small" > {getting ? : }
{pendingSetsToShow.map((setWithNames) => ( selectSet(setWithNames.set)} /> ))} {completedSetsToShow.length > 0 && ( <> setCompletedOpen((oldCompletedOpen) => !oldCompletedOpen) } > completed {completedOpen ? ( ) : ( )} {completedSetsToShow.map((setWithNames) => ( selectSet(setWithNames.set)} /> ))} )} {(phaseGroup.bracketType === 3 || phaseGroup.bracketType === 4) && phaseGroup.sets.completedSets.length > 0 && phaseGroup.sets.pendingSets.length === 0 && ( seed.entrant) .map((seed) => seed.entrant!)} selectSet={(set: Set) => selectSet(set)} /> )}
) ); } function PhaseView({ phase, initiallyOpen, ancestorsOpen, searchSubstr, vlerkMode, selectedPhaseGroupId, getPhase, getPhaseGroup, selectSet, }: { phase: Phase; initiallyOpen: boolean; ancestorsOpen: boolean; searchSubstr: string; vlerkMode: boolean; selectedPhaseGroupId: number | undefined; getPhase: (id: number) => Promise; getPhaseGroup: (id: number) => Promise; selectSet: (set: Set, phaseGroup: SelectedPhaseGroup) => Promise; }) { const [getting, setGetting] = useState(false); const [open, setOpen] = useState(initiallyOpen); const get = async () => { setGetting(true); await getPhase(phase.id); setGetting(false); }; return ( <> { if (!open && phase.phaseGroups.length === 0) { get(); } setOpen((oldOpen) => !oldOpen); }} sx={{ typography: 'caption' }} > {open ? : } {phase.name} {'\u00A0'}({phase.id}) { event.stopPropagation(); get(); }} size="small" > {getting ? : } {phase.phaseGroups.map((phaseGroup) => ( selectSet(set, { id: phaseGroup.id, name: phaseGroup.name, bracketType: phaseGroup.bracketType, hasSiblings: phase.phaseGroups.length > 1, waveId: phaseGroup.waveId, winnersTargetPhaseId: phaseGroup.winnersTargetPhaseId, }) } /> ))} ); } function EventView({ event, initiallyOpen, searchSubstr, vlerkMode, selectedPhaseId, selectedPhaseGroupId, getEvent, getPhase, getPhaseGroup, selectSet, }: { event: Event; initiallyOpen: boolean; searchSubstr: string; vlerkMode: boolean; selectedPhaseId: number | undefined; selectedPhaseGroupId: number | undefined; getEvent: (id: number) => Promise; getPhase: (id: number) => Promise; getPhaseGroup: (id: number) => Promise; selectSet: ( set: Set, phaseGroup: SelectedPhaseGroup, phase: SelectedPhase, ) => Promise; }) { const [getting, setGetting] = useState(false); const [open, setOpen] = useState(initiallyOpen); const get = async () => { setGetting(true); await getEvent(event.id); setGetting(false); }; return ( <> { if (!open && event.phases.length === 0) { get(); } setOpen((oldOpen) => !oldOpen); }} sx={{ typography: 'caption' }} > {open ? : } {event.name} {'\u00A0'}({event.id}) { ev.stopPropagation(); get(); }} size="small" > {getting ? : } {event.phases.map((phase) => ( selectSet(set, phaseGroup, { id: phase.id, name: phase.name, hasSiblings: event.phases.length > 1, }) } /> ))} ); } export default function StartggView({ searchSubstr, tournament, vlerkMode, selectedEventId, selectedPhaseId, selectedPhaseGroupId, getEvent, getPhase, getPhaseGroup, selectSet, }: { searchSubstr: string; tournament: Tournament; vlerkMode: boolean; selectedEventId: number | undefined; selectedPhaseId: number | undefined; selectedPhaseGroupId: number | undefined; getEvent: (id: number) => Promise; getPhase: (id: number) => Promise; getPhaseGroup: (id: number) => Promise; selectSet: ( set: Set, phaseGroup: SelectedPhaseGroup, phase: SelectedPhase, event: SelectedEvent, ) => Promise; }) { return ( {tournament.events.map((event) => ( selectSet(set, phaseGroup, phase, { id: event.id, name: event.name, slug: event.slug, hasSiblings: tournament.events.length > 1, }) } /> ))} ); }