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