]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/rounds/SeedButton.js
tracker items as svg
[alttp.git] / resources / js / components / rounds / SeedButton.js
1 import PropTypes from 'prop-types';
2 import React, { useState } from 'react';
3 import { Button } from 'react-bootstrap';
4 import { useTranslation } from 'react-i18next';
5
6 import SeedDialog from './SeedDialog';
7 import { maySetSeed } from '../../helpers/permissions';
8 import { useUser } from '../../hooks/user';
9
10 const SeedButton = ({ round, tournament }) => {
11         const [showDialog, setShowDialog] = useState(false);
12
13         const { t } = useTranslation();
14         const { user } = useUser();
15
16         if (round.seed) {
17                 return <>
18                         <Button href={round.seed} target="_blank" variant="primary">
19                                 {t('rounds.seed')}
20                         </Button>
21                         {round.spoiler ?
22                                 <Button
23                                         className="ms-2"
24                                         href={round.spoiler}
25                                         target="_blank"
26                                         variant="outline-primary"
27                                 >
28                                         {t('rounds.spoiler')}
29                                 </Button>
30                         : null}
31                 </>;
32         }
33         if (maySetSeed(user, tournament, round)) {
34                 return <>
35                         <SeedDialog
36                                 onHide={() => setShowDialog(false)}
37                                 round={round}
38                                 show={showDialog}
39                         />
40                         <Button onClick={() => setShowDialog(true)} variant="outline-primary">
41                                 {t('rounds.setSeed')}
42                         </Button>
43                 </>;
44         }
45         return t('rounds.noSeed');
46 };
47
48 SeedButton.propTypes = {
49         round: PropTypes.shape({
50                 seed: PropTypes.string,
51                 spoiler: PropTypes.string,
52         }),
53         tournament: PropTypes.shape({
54         }),
55 };
56
57 export default SeedButton;