fork/replay-manager-for-slippi

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

jmlee337persist manual names5f6c213

2.3.5
1.5 KiB64 linesraw
1import {
2  Button,
3  DialogActions,
4  DialogContent,
5  DialogContentText,
6  DialogTitle,
7  TextField,
8} from '@mui/material';
9import { FormEvent } from 'react';
10
11const placeholder = `Player 1
12Player 2
13Player 3
14Player 4
15...`;
16
17export default function ManualNamesForm({
18  close,
19  manualNames,
20  setManualNames,
21}: {
22  close: () => void;
23  manualNames: string[];
24  setManualNames: (manualNames: string[]) => Promise<void>;
25}) {
26  return (
27    <>
28      <DialogTitle>Enter Player Names</DialogTitle>
29      <form
30        onSubmit={async (event: FormEvent<HTMLFormElement>) => {
31          const target = event.target as typeof event.target & {
32            names: { value: string };
33          };
34          const rawNames = target.names.value;
35          event.preventDefault();
36          event.stopPropagation();
37          if (rawNames) {
38            await setManualNames(rawNames.split('\n'));
39            close();
40          }
41        }}
42      >
43        <DialogContent style={{ paddingTop: 0 }}>
44          <DialogContentText>One per line</DialogContentText>
45          <TextField
46            multiline
47            minRows={8}
48            maxRows={16}
49            name="names"
50            placeholder={placeholder}
51            defaultValue={
52              manualNames.length > 0 ? manualNames.join('\n') : undefined
53            }
54          />
55        </DialogContent>
56        <DialogActions>
57          <Button type="submit" variant="contained">
58            Set!
59          </Button>
60        </DialogActions>
61      </form>
62    </>
63  );
64}