fork/replay-manager-for-slippi
git clone https://git.julia.blue/fork/replay-manager-for-slippi
ddc617a
2.3.4
1import { 2Box , 3CircularProgress , 4Collapse , 5IconButton , 6ListItemButton , 7Tooltip , 8Typography , 9} from '@mui/material' ; 10import { 11KeyboardArrowDown , 12KeyboardArrowRight , 13KeyboardArrowUp , 14PlayArrow , 15Refresh , 16} from '@mui/icons-material' ; 17import { useState } from 'react' ; 18import { ChallongeTournament , Set , SetWithNames , State } from '../common/types' ; 19import SetViewInner from './SetView' ; 20import filterSets from './filterSets' ; 21import TiebreakerDialog from './TiebreakerDialog' ; 22 23function SetView ({ 24 setWithNames, 25 selectSet, 26} :{ 27setWithNames :SetWithNames ; 28selectSet :( set :Set ) => void ; 29}) { 30return ( 31< ListItemButton 32dense 33disableGutters 34onClick = {() => { 35selectSet ( setWithNames . set ); 36}} 37> 38< SetViewInner 39entrant1Names = { setWithNames . entrant1Names } 40entrant1Score = { setWithNames . set . entrant1Score } 41entrant1Win = { setWithNames . set . entrant1Id === setWithNames . set . winnerId } 42entrant2Names = { setWithNames . entrant2Names } 43entrant2Score = { setWithNames . set . entrant2Score } 44fullRoundText = { setWithNames . set . fullRoundText } 45showScores = { setWithNames . set . state === State . COMPLETED } 46state = { setWithNames . set . state } 47stream = { setWithNames . set . stream } 48station = { setWithNames . set . station } 49wasReported = { false } 50updatedAtMs = { setWithNames . set . updatedAtMs } 51/> 52</ ListItemButton > 53); 54} 55 56export default function ChallongeView ({ 57 searchSubstr, 58 tournament, 59 getChallongeTournament, 60 selectSet, 61} :{ 62searchSubstr :string ; 63tournament :ChallongeTournament ; 64getChallongeTournament :() => Promise < void >; 65selectSet :( set :Set ) => void ; 66}) { 67const [ open , setOpen ] = useState ( true ); 68const [ completedOpen , setCompletedOpen ] = useState ( false ); 69const [ getting , setGetting ] = useState ( false ); 70const get = async () => { 71setGetting ( true ); 72await getChallongeTournament (); 73setGetting ( false ); 74}; 75const pendingSetsToShow = filterSets ( 76tournament . sets . pendingSets , 77searchSubstr , 78); 79const completedSetsToShow = filterSets ( 80tournament . sets . completedSets , 81searchSubstr , 82); 83return ( 84( ! searchSubstr || 85pendingSetsToShow . length > 0 || 86completedSetsToShow . length > 0 ) && ( 87< Box bgcolor = "white" > 88< ListItemButton 89dense 90disableGutters 91onClick = {() => { 92setOpen ( ! open ); 93}} 94sx = {{ typography :'caption' }} 95> 96{ open ?< KeyboardArrowDown /> :< KeyboardArrowRight />} 97< div 98style = {{ 99overflowX :'hidden' , 100textOverflow :'ellipsis' , 101whiteSpace :'nowrap' , 102}} 103> 104{ tournament . name } 105</ div > 106< Box > 107< Tooltip arrow title = "Refresh tournament" > 108< IconButton 109onClick = {( ev ) => { 110ev . stopPropagation (); 111get (); 112}} 113size = "small" 114> 115{ getting ?< CircularProgress size = "24px" /> :< Refresh />} 116</ IconButton > 117</ Tooltip > 118</ Box > 119{ tournament . state === State . PENDING && ( 120< Box > 121< Tooltip arrow title = "Start tournament on website" > 122< IconButton 123onClick = {( ev ) => { 124ev . stopPropagation (); 125window . open ( `//challonge.com/ ${ tournament . slug } ` ); 126}} 127size = "small" 128> 129< PlayArrow /> 130</ IconButton > 131</ Tooltip > 132</ Box > 133)} 134</ ListItemButton > 135< Collapse in = { open }> 136< div > 137{ pendingSetsToShow . map (( setWithNames ) => ( 138< SetView 139key = { setWithNames . set . id } 140setWithNames = { setWithNames } 141selectSet = { selectSet } 142/> 143))} 144{ completedSetsToShow . length > 0 && ( 145<> 146< ListItemButton 147dense 148onClick = {() => setCompletedOpen ( ! completedOpen )} 149> 150< Typography 151alignItems = "center" 152display = "flex" 153justifyContent = "right" 154variant = "subtitle2" 155width = "100%" 156> 157completed 158{ completedOpen ?( 159< KeyboardArrowUp /> 160) :( 161< KeyboardArrowDown /> 162)} 163</ Typography > 164</ ListItemButton > 165< Collapse in = { completedOpen }> 166{ completedSetsToShow . map (( setWithNames ) => ( 167< SetView 168key = { setWithNames . set . id } 169setWithNames = { setWithNames } 170selectSet = { selectSet } 171/> 172))} 173</ Collapse > 174</> 175)} 176{( tournament . tournamentType === 'swiss' || 177tournament . tournamentType === 'round robin' ) && 178tournament . sets . completedSets . length > 0 && 179tournament . sets . pendingSets . length === 0 && ( 180< TiebreakerDialog 181entrants = { tournament . entrants } 182selectSet = { async ( set :Set ) => { 183selectSet ( set ); 184}} 185/> 186)} 187</ div > 188</ Collapse > 189</ Box > 190) 191); 192}