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 { Phase, Tournament, Event } from '@parry-gg/client'; import { State, ParryggBracket, Set, SetWithNames, SelectedPhaseGroup, SelectedPhase, SelectedEvent, } from '../common/types'; import SetViewInner from './SetView'; import filterSets from './filterSets'; const Block = styled.div` padding-left: 8px; `; const Name = styled.div` overflow-x: hidden; text-overflow: ellipsis; white-space: nowrap; `; function SetView({ setWithNames, vlerkMode, selectSet, }: { setWithNames: SetWithNames; vlerkMode: boolean; selectSet: () => Promise; }) { const { set: { entrant1Id, entrant1Score, entrant2Score, winnerId, fullRoundText, state, stream, station, updatedAtMs, }, entrant1Names, entrant2Names, } = setWithNames; const isCompleted = state === State.COMPLETED; return ( { selectSet(); }} > ); } function BracketView({ bracket, initiallyOpen, searchSubstr, vlerkMode, getBracket, selectSet, }: { bracket: ParryggBracket; initiallyOpen: boolean; searchSubstr: string; vlerkMode: boolean; getBracket: (id: string) => 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 getBracket(bracket.id); setGetting(false); }; const pendingSetsToShow = filterSets( bracket.sets?.pendingSets ?? [], searchSubstr, ); const completedSetsToShow = filterSets( bracket.sets?.completedSets ?? [], searchSubstr, ); return ( (!searchSubstr || pendingSetsToShow.length > 0 || completedSetsToShow.length > 0) && ( <> { if (!open && bracket.matchesList.length === 0) { get(); } setOpen(!open); }} sx={{ typography: 'caption' }} > {open ? : } Bracket ({bracket.slug}) { event.stopPropagation(); get(); }} size="small" > {getting ? : }
{pendingSetsToShow.map((setWithNames) => { const { set } = setWithNames; return ( selectSet(set)} /> ); })} {completedSetsToShow.length > 0 && ( <> setCompletedOpen(!completedOpen)} > completed {completedOpen ? ( ) : ( )} {completedSetsToShow.map((setWithNames) => { const { set } = setWithNames; return ( selectSet(set)} /> ); })} )}
) ); } function PhaseView({ phase, initiallyOpen, searchSubstr, vlerkMode, selectedBracketId, getPhase, getBracket, selectSet, }: { phase: Phase.AsObject; initiallyOpen: boolean; searchSubstr: string; vlerkMode: boolean; selectedBracketId: string | undefined; getPhase: (id: string) => Promise; getBracket: (id: string) => Promise; selectSet: (set: Set, bracket: 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.bracketsList.length === 0) { get(); } setOpen(!open); }} sx={{ typography: 'caption' }} > {open ? : } Phase ({phase.slug}) { event.stopPropagation(); get(); }} size="small" > {getting ? : } {phase.bracketsList.map((bracket) => ( selectSet(set, { id: bracket.id, name: bracket.slug, hasSiblings: phase.bracketsList.length > 1, bracketType: bracket.type, waveId: null, winnersTargetPhaseId: null, }) } /> ))} ); } function EventView({ event, initiallyOpen, searchSubstr, vlerkMode, selectedPhaseId, selectedBracketId, getEvent, getPhase, getBracket, selectSet, }: { event: Event.AsObject; initiallyOpen: boolean; searchSubstr: string; vlerkMode: boolean; selectedPhaseId: string | undefined; selectedBracketId: string | undefined; getEvent: (id: string) => Promise; getPhase: (id: string) => Promise; getBracket: (id: string) => Promise; selectSet: ( set: Set, bracket: 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.phasesList.length === 0) { get(); } setOpen(!open); }} sx={{ typography: 'caption' }} > {open ? : } {event.name} { ev.stopPropagation(); get(); }} size="small" > {getting ? : } {event.phasesList.map((phase) => ( selectSet(set, bracket, { id: phase.id, name: phase.slug, hasSiblings: event.phasesList.length > 1, }) } /> ))} ); } export default function ParryggView({ searchSubstr, tournament, vlerkMode, selectedEventId, selectedPhaseId, selectedBracketId, getEvent, getPhase, getBracket, selectSet, }: { searchSubstr: string; tournament: Tournament.AsObject | undefined; vlerkMode: boolean; selectedEventId: string | undefined; selectedPhaseId: string | undefined; selectedBracketId: string | undefined; getEvent: (id: string) => Promise; getPhase: (id: string) => Promise; getBracket: (id: string) => Promise; selectSet: ( set: Set, bracket: SelectedPhaseGroup, phase: SelectedPhase, event: SelectedEvent, ) => Promise; }) { const events = tournament?.eventsList || []; return ( {events.map((event) => ( selectSet(set, bracket, phase, { id: event.id, name: event.name, slug: event.slug, hasSiblings: events.length > 1, }) } /> ))} ); }