fork/replay-manager-for-slippi

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

Nicoletsgg phase group entrants -> seedsac16564

2.3.6
3.3 KiB136 linesraw
1import React, { useEffect, useState } from 'react';
2import {
3  AppBar,
4  CircularProgress,
5  IconButton,
6  List,
7  ListItem,
8  ListItemText,
9  Stack,
10  Toolbar,
11  Tooltip,
12  Typography,
13} from '@mui/material';
14import { createRoot } from 'react-dom/client';
15import { Refresh } from '@mui/icons-material';
16import { RendererPool, RendererWave, Seed } from '../common/types';
17
18function SeedListItemContents({ seed }: { seed: Seed }) {
19  let ret: any = '\xa0';
20  if (seed.entrant) {
21    ret = seed.entrant.participants
22      .map((participant) => participant.displayName)
23      .join(' / ');
24  } else if (seed.placeholder) {
25    ret = <span style={{ fontStyle: 'italic' }}>{seed.placeholder}</span>;
26  }
27  return ret;
28}
29
30function Pool({ pool }: { pool: RendererPool }) {
31  return (
32    <Stack width="200px">
33      <Typography variant="caption">{pool.name}</Typography>
34      <List>
35        {pool.seeds.map((seed) => (
36          <ListItemText
37            key={seed.id}
38            slotProps={{
39              primary: {
40                style: {
41                  overflowX: 'hidden',
42                  textOverflow: 'ellipsis',
43                  whiteSpace: 'nowrap',
44                },
45              },
46            }}
47          >
48            <SeedListItemContents seed={seed} />
49          </ListItemText>
50        ))}
51      </List>
52    </Stack>
53  );
54}
55
56function WaveEl({ wave }: { wave: RendererWave }) {
57  return (
58    <ListItem
59      style={{
60        display: 'flex',
61        flexDirection: 'row',
62        flexWrap: 'wrap',
63        alignItems: 'start',
64        gap: '8px',
65      }}
66    >
67      {wave.pools.map((pool) => (
68        <Pool key={pool.id} pool={pool} />
69      ))}
70    </ListItem>
71  );
72}
73
74function Entrants() {
75  const [waves, setWaves] = useState<RendererWave[]>([]);
76  const [gettingWaves, setGettingWaves] = useState(true);
77
78  useEffect(() => {
79    (async () => {
80      try {
81        setWaves(await window.electron.getPoolsByWave());
82      } catch {
83        // just catch
84      }
85      setGettingWaves(false);
86    })();
87  }, []);
88
89  return (
90    <>
91      <AppBar position="fixed" color="inherit">
92        <Toolbar disableGutters style={{ justifyContent: 'space-between' }}>
93          <Typography variant="h5" marginLeft="16px">
94            Seeds by Pool
95          </Typography>
96          <Tooltip arrow title="Refresh">
97            <IconButton
98              disabled={gettingWaves}
99              onClick={async () => {
100                setGettingWaves(true);
101                try {
102                  setWaves(await window.electron.getPoolsByWave());
103                } catch {
104                  // just catch
105                }
106                setGettingWaves(false);
107              }}
108            >
109              <Refresh />
110            </IconButton>
111          </Tooltip>
112        </Toolbar>
113      </AppBar>
114      {gettingWaves ? (
115        <Stack
116          width="100%"
117          height="100%"
118          alignItems="center"
119          justifyContent="center"
120        >
121          <CircularProgress size="24px" />
122        </Stack>
123      ) : (
124        <List disablePadding style={{ marginTop: '64px' }}>
125          {waves.map((wave) => (
126            <WaveEl key={wave.id} wave={wave} />
127          ))}
128        </List>
129      )}
130    </>
131  );
132}
133
134const container = document.getElementById('root') as HTMLElement;
135const root = createRoot(container);
136root.render(<Entrants />);