import { RestartAlt } from '@mui/icons-material'; import { Button, CircularProgress, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, IconButton, Tooltip, } from '@mui/material'; import { useCallback, useState } from 'react'; import { Mode, Set, State } from '../common/types'; import SetView from './SetView'; import { assertInteger } from '../common/asserts'; export default function ResetSet({ mode, selectedSet, }: { mode: Mode; selectedSet: Set; }) { const [confirmOpen, setConfirmOpen] = useState(false); const [errorOpen, setErrorOpen] = useState(false); const [error, setError] = useState(''); const [resetting, setResetting] = useState(false); const reset = useCallback(async () => { setResetting(true); try { if (mode === Mode.STARTGG) { await window.electron.resetSet(assertInteger(selectedSet.id)); } else if (mode === Mode.OFFLINE_MODE) { await window.electron.resetOfflineModeSet( assertInteger(selectedSet.id), ); } setConfirmOpen(false); } catch (e: any) { setError(e.toString()); setErrorOpen(true); } finally { setResetting(false); } }, [mode, selectedSet.id]); return ( <> { if ( selectedSet.state === State.CALLED || selectedSet.state === State.STARTED ) { reset(); } else { setConfirmOpen(true); } }} > {resetting ? : } setConfirmOpen(false)}> Reset Set? ({ name: participant.displayName }), )} entrant1Score={selectedSet.entrant1Score} entrant1Win={selectedSet.winnerId === selectedSet.entrant1Id} entrant2Names={selectedSet.entrant2Participants.map( (participant) => ({ name: participant.displayName }), )} entrant2Score={selectedSet.entrant2Score} fullRoundText={selectedSet.fullRoundText} showScores={selectedSet.state === State.COMPLETED} state={selectedSet.state} stream={selectedSet.stream} station={selectedSet.station} wasReported={false} updatedAtMs={selectedSet.updatedAtMs} /> : } onClick={reset} variant="contained" > Reset { setErrorOpen(false); setError(''); }} > Reset error! {error} { setErrorOpen(false); setError(''); }} > Close > ); }