fork/replay-manager-for-slippi
git clone https://git.julia.blue/fork/replay-manager-for-slippi
f83b198
2.5.1
1import { RestartAlt } from '@mui/icons-material' ; 2import { 3Button , 4CircularProgress , 5Dialog , 6DialogActions , 7DialogContent , 8DialogContentText , 9DialogTitle , 10IconButton , 11Tooltip , 12} from '@mui/material' ; 13import { useCallback , useState } from 'react' ; 14import { Mode , Set , State } from '../common/types' ; 15import SetView from './SetView' ; 16import { assertInteger } from '../common/asserts' ; 17 18export default function ResetSet ({ 19 mode, 20 selectedSet, 21} :{ 22mode :Mode ; 23selectedSet :Set ; 24}) { 25const [ confirmOpen , setConfirmOpen ] = useState ( false ); 26const [ errorOpen , setErrorOpen ] = useState ( false ); 27const [ error , setError ] = useState ( '' ); 28const [ resetting , setResetting ] = useState ( false ); 29 30const reset = useCallback ( async () => { 31setResetting ( true ); 32try { 33if ( mode === Mode . STARTGG ) { 34await window . electron . resetSet ( assertInteger ( selectedSet . id )); 35} else if ( mode === Mode . OFFLINE_MODE ) { 36await window . electron . resetOfflineModeSet ( 37assertInteger ( selectedSet . id ), 38); 39} 40setConfirmOpen ( false ); 41} catch ( e :any ) { 42setError ( e . toString ()); 43setErrorOpen ( true ); 44} finally { 45setResetting ( false ); 46} 47}, [ mode , selectedSet . id ]); 48 49return ( 50<> 51< Tooltip arrow title = "Reset set" > 52< div > 53< IconButton 54color = "primary" 55disabled = { 56! Number . isInteger ( selectedSet . id ) || 57( selectedSet . id as number ) <= 0 || 58selectedSet . state === State . PENDING || 59resetting || 60( mode !== Mode . STARTGG && mode !== Mode . OFFLINE_MODE ) 61} 62size = "small" 63onClick = {() => { 64if ( 65selectedSet . state === State . CALLED || 66selectedSet . state === State . STARTED 67) { 68reset (); 69} else { 70setConfirmOpen ( true ); 71} 72}} 73> 74{ resetting ?< CircularProgress size = "24px" /> :< RestartAlt />} 75</ IconButton > 76</ div > 77</ Tooltip > 78< Dialog open = { confirmOpen } onClose = {() => setConfirmOpen ( false )}> 79< DialogTitle > Reset Set? </ DialogTitle > 80< DialogContent style = {{ width :'300px' }}> 81< SetView 82entrant1Names = { selectedSet . entrant1Participants . map ( 83( participant ) => ({ name :participant . displayName }), 84)} 85entrant1Score = { selectedSet . entrant1Score } 86entrant1Win = { selectedSet . winnerId === selectedSet . entrant1Id } 87entrant2Names = { selectedSet . entrant2Participants . map ( 88( participant ) => ({ name :participant . displayName }), 89)} 90entrant2Score = { selectedSet . entrant2Score } 91fullRoundText = { selectedSet . fullRoundText } 92showScores = { selectedSet . state === State . COMPLETED } 93state = { selectedSet . state } 94stream = { selectedSet . stream } 95station = { selectedSet . station } 96wasReported = { false } 97updatedAtMs = { selectedSet . updatedAtMs } 98/> 99</ DialogContent > 100< DialogActions > 101< Button 102color = "error" 103disabled = { 104! Number . isInteger ( selectedSet . id ) || 105( selectedSet . id as number ) <= 0 || 106selectedSet . state === State . PENDING || 107resetting 108} 109endIcon = { 110resetting ?< CircularProgress size = "24px" /> :< RestartAlt /> 111} 112onClick = { reset } 113variant = "contained" 114> 115Reset 116</ Button > 117</ DialogActions > 118</ Dialog > 119< Dialog 120open = { errorOpen } 121onClose = {() => { 122setErrorOpen ( false ); 123setError ( '' ); 124}} 125> 126< DialogTitle > Reset error! </ DialogTitle > 127< DialogContent > 128< DialogContentText >{ error }</ DialogContentText > 129</ DialogContent > 130< DialogActions > 131< Button 132onClick = {() => { 133setErrorOpen ( false ); 134setError ( '' ); 135}} 136> 137Close 138</ Button > 139</ DialogActions > 140</ Dialog > 141</> 142); 143}