fork/replay-manager-for-slippi

git clone https://git.julia.blue/fork/replay-manager-for-slippi

Nicoletdisambiguate context (sgg) `id` vs `internalId`e87008e

2.5.0
3.2 KiB108 linesraw
1import {
2  Dialog,
3  DialogContent,
4  DialogTitle,
5  ListItemButton,
6  ListItemText,
7  Typography,
8} from '@mui/material';
9import { useState } from 'react';
10import { Entrant, Set, State } from '../common/types';
11
12export default function TiebreakerDialog({
13  entrants,
14  selectSet,
15}: {
16  entrants: Entrant[];
17  selectSet: (set: Set) => Promise<void>;
18}) {
19  const [open, setOpen] = useState(false);
20  const [selectedEntrant, setSelectedEntrant] = useState<Entrant>({
21    id: 0,
22    participants: [],
23  });
24  return (
25    <>
26      <ListItemButton
27        dense
28        onClick={async () => {
29          setOpen(true);
30        }}
31      >
32        <Typography
33          alignItems="center"
34          display="flex"
35          justifyContent="right"
36          variant="subtitle2"
37          width="100%"
38        >
39          tiebreaker...
40        </Typography>
41      </ListItemButton>
42      <Dialog
43        open={open}
44        onClose={() => {
45          setSelectedEntrant({ id: 0, participants: [] });
46          setOpen(false);
47        }}
48      >
49        <DialogTitle>Generate Tiebreaker Set...</DialogTitle>
50        <DialogContent>
51          {entrants.map((entrant) => (
52            <ListItemButton
53              dense
54              key={entrant.id}
55              style={{
56                backgroundColor:
57                  selectedEntrant.id === entrant.id ? '#5BCEFA' : undefined,
58              }}
59              onClick={() => {
60                if (selectedEntrant.id) {
61                  if (selectedEntrant.id === entrant.id) {
62                    setSelectedEntrant({ id: 0, participants: [] });
63                  } else {
64                    selectSet({
65                      id: -1,
66                      sggId: null,
67                      state: State.PENDING,
68                      round: Number.MAX_SAFE_INTEGER,
69                      fullRoundText: 'Tie-Breaker',
70                      entrant1Id: selectedEntrant.id,
71                      entrant1Participants: selectedEntrant.participants,
72                      entrant2Id: entrant.id,
73                      entrant2Participants: entrant.participants,
74                      wasReported: false,
75                      entrant1Score: null,
76                      entrant2Score: null,
77                      gameScores: [],
78                      ordinal: null,
79                      stream: null,
80                      station: null,
81                      winnerId: null,
82                      updatedAtMs: 0,
83                      completedAtMs: 0,
84                    });
85                    setSelectedEntrant({ id: 0, participants: [] });
86                    setOpen(false);
87                  }
88                } else {
89                  setSelectedEntrant({
90                    id: entrant.id,
91                    participants: entrant.participants,
92                  });
93                }
94              }}
95            >
96              <ListItemText>
97                <span>{entrant.participants[0].displayName}</span>
98                {entrant.participants.length > 1 && (
99                  <span>{entrant.participants[1].displayName}</span>
100                )}
101              </ListItemText>
102            </ListItemButton>
103          ))}
104        </DialogContent>
105      </Dialog>
106    </>
107  );
108}