Skip to content

Commit

Permalink
manual reporting button/dialog for DQ and W/L #13
Browse files Browse the repository at this point in the history
  • Loading branch information
jmlee337 committed Mar 4, 2024
1 parent e407a34 commit 4983033
Show file tree
Hide file tree
Showing 2 changed files with 239 additions and 60 deletions.
98 changes: 38 additions & 60 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import CopyControls from './CopyControls';
import SetControls from './SetControls';
import ErrorDialog from './ErrorDialog';
import Settings from './Settings';
import ManualReport from './ManualReport';

const Bottom = styled(Paper)`
height: 147px;
Expand Down Expand Up @@ -784,14 +785,20 @@ function Hello() {
{selectedSet.fullRoundText} ({selectedSet.id})
</Typography>
{selectedSet.state === 2 && (
<Tooltip placement="top" title="Started">
<HourglassTop fontSize="inherit" />
</Tooltip>
<>
&nbsp;
<Tooltip title="Started">
<HourglassTop fontSize="inherit" />
</Tooltip>
</>
)}
{selectedSet.state === 3 && (
<Tooltip placement="top" title="Finished">
<Backup fontSize="inherit" />
</Tooltip>
<>
&nbsp;
<Tooltip placement="top" title="Finished">
<Backup fontSize="inherit" />
</Tooltip>
</>
)}
</Stack>
<Tooltip arrow title="Drag or select players!">
Expand Down Expand Up @@ -845,60 +852,31 @@ function Hello() {
</>
)}
</Stack>
<Stack direction="row" paddingTop="8px" spacing="8px">
<Stack direction="row" width="50%">
<DroppableChip
active
label={dq.displayName || 'DQ'}
outlined
selectedChipData={selectedChipData}
style={{ width: '100%' }}
onClickOrDrop={(displayName: string, entrantId: number) => {
const newOverrides = [
{ displayName: '', entrantId: 0 },
{ displayName: '', entrantId: 0 },
{ displayName: '', entrantId: 0 },
{ displayName: '', entrantId: 0 },
];
selectedReplays.forEach((replay) => {
replay.selected = false;
replay.players.forEach((player, i) => {
player.playerOverrides = { ...newOverrides[i] };
});
});
const newReplays = Array.from(replays);
setOverrides(newOverrides);
setReplays(newReplays);
setDq({ displayName, entrantId });
resetSelectedChipData();
}}
/>
</Stack>
<Stack
direction="row"
justifyContent="flex-end"
flexGrow={1}
spacing="8px"
>
<Tooltip title="Start Match">
<div>
<IconButton
color="primary"
disabled={!(selectedSet.id && selectedSet.state < 2)}
size="small"
onClick={() => startSet(selectedSet.id)}
>
<HourglassTop />
</IconButton>
</div>
</Tooltip>
<SetControls
reportSet={reportSet}
dqId={dq.entrantId}
selectedReplays={selectedReplays}
set={selectedSet}
/>
</Stack>
<Stack
direction="row"
justifyContent="flex-end"
paddingTop="8px"
spacing="8px"
>
<Tooltip title="Start Match">
<div>
<IconButton
color="primary"
disabled={!(selectedSet.id && selectedSet.state < 2)}
size="small"
onClick={() => startSet(selectedSet.id)}
>
<HourglassTop />
</IconButton>
</div>
</Tooltip>
<ManualReport reportSet={reportSet} selectedSet={selectedSet} />
<SetControls
reportSet={reportSet}
dqId={dq.entrantId}
selectedReplays={selectedReplays}
set={selectedSet}
/>
</Stack>
</Stack>
</BottomColumns>
Expand Down
201 changes: 201 additions & 0 deletions src/renderer/ManualReport.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
import { useState } from 'react';
import {
Button,
CircularProgress,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
IconButton,
Stack,
Tooltip,
} from '@mui/material';
import { Backup, HourglassTop, SaveAs } from '@mui/icons-material';
import styled from '@emotion/styled';
import { Set, StartggSet } from '../common/types';

const EntrantNames = styled(Stack)`
flex-grow: 1;
min-width: 0;
`;
const Name = styled.div`
overflow-x: hidden;
text-overflow: ellipsis;
white-space: nowrap;
`;

export default function ManualReport({
reportSet,
selectedSet,
}: {
reportSet: (set: StartggSet, update: boolean) => Promise<void>;
selectedSet: Set;
}) {
const [open, setOpen] = useState(false);
const [reporting, setReporting] = useState(false);
const [entrant1Dq, setEntrant1Dq] = useState(false);
const [entrant2Dq, setEntrant2Dq] = useState(false);
const [entrant1Win, setEntrant1Win] = useState(false);
const [entrant2Win, setEntrant2Win] = useState(false);
const resetForm = () => {
setEntrant1Dq(false);
setEntrant2Dq(false);
setEntrant1Win(false);
setEntrant2Win(false);
};

let winnerId = 0;
if (entrant1Win || entrant2Dq) {
winnerId = selectedSet.entrant1Id;
} else if (entrant2Win || entrant1Dq) {
winnerId = selectedSet.entrant2Id;
}
const startggSet: StartggSet = {
setId: selectedSet.id,
winnerId,
isDQ: entrant1Dq || entrant2Dq,
gameData: [],
};

return (
<>
<Tooltip title="Report Manually">
<div>
<IconButton
color="primary"
disabled={!selectedSet.id || selectedSet.state === 3}
size="small"
onClick={() => {
resetForm();
setOpen(true);
}}
>
<SaveAs />
</IconButton>
</div>
</Tooltip>
<Dialog open={open} onClose={() => setOpen(false)}>
<DialogTitle>Report set manually</DialogTitle>
<DialogContent sx={{ width: '300px' }}>
<Stack
direction="row"
alignItems="center"
justifyContent="center"
typography="caption"
>
{selectedSet.fullRoundText}
{selectedSet.state === 2 && (
<>
&nbsp;
<Tooltip title="Started">
<HourglassTop fontSize="small" />
</Tooltip>
</>
)}
{selectedSet.state === 3 && (
<>
&nbsp;
<Tooltip title="Finished">
<Backup fontSize="small" />
</Tooltip>
</>
)}
</Stack>
<Stack
alignItems="end"
marginTop="4px"
spacing="8px"
sx={{ typography: 'body2' }}
>
<Stack
alignItems="center"
direction="row"
justifyContent="space-between"
width="100%"
>
<EntrantNames>
<Name>{selectedSet.entrant1Names[0]}</Name>
{selectedSet.entrant1Names.length > 1 && (
<Name>{selectedSet.entrant1Names[1]}</Name>
)}
</EntrantNames>
<Stack direction="row" spacing="8px">
<Button
color="secondary"
variant={entrant1Dq ? 'contained' : 'outlined'}
onClick={() => {
resetForm();
setEntrant1Dq(true);
}}
>
DQ
</Button>
<Button
color="secondary"
variant={entrant1Win ? 'contained' : 'outlined'}
onClick={() => {
resetForm();
setEntrant1Win(true);
}}
>
W
</Button>
</Stack>
</Stack>
<Stack
alignItems="center"
direction="row"
justifyContent="space-between"
width="100%"
>
<EntrantNames>
<Name>{selectedSet.entrant2Names[0]}</Name>
{selectedSet.entrant2Names.length > 1 && (
<Name>{selectedSet.entrant2Names[1]}</Name>
)}
</EntrantNames>
<Stack direction="row" spacing="8px">
<Button
color="secondary"
variant={entrant2Dq ? 'contained' : 'outlined'}
onClick={() => {
resetForm();
setEntrant2Dq(true);
}}
>
DQ
</Button>
<Button
color="secondary"
variant={entrant2Win ? 'contained' : 'outlined'}
onClick={() => {
resetForm();
setEntrant2Win(true);
}}
>
W
</Button>
</Stack>
</Stack>
</Stack>
</DialogContent>
<DialogActions>
<Button
disabled={reporting}
endIcon={reporting ? <CircularProgress size="24px" /> : <SaveAs />}
onClick={async () => {
setReporting(true);
await reportSet(startggSet, selectedSet.state === 3);
resetForm();
setOpen(false);
setReporting(false);
}}
variant="contained"
>
Report Manually
</Button>
</DialogActions>
</Dialog>
</>
);
}

0 comments on commit 4983033

Please sign in to comment.