]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/rounds/SeedButton.js
allow setting seeds
[alttp.git] / resources / js / components / rounds / SeedButton.js
diff --git a/resources/js/components/rounds/SeedButton.js b/resources/js/components/rounds/SeedButton.js
new file mode 100644 (file)
index 0000000..1d68b6a
--- /dev/null
@@ -0,0 +1,46 @@
+import PropTypes from 'prop-types';
+import React, { useState } from 'react';
+import { Button } from 'react-bootstrap';
+import { withTranslation } from 'react-i18next';
+
+import SeedDialog from './SeedDialog';
+import { maySetSeed } from '../../helpers/permissions';
+import { withUser } from '../../helpers/UserContext';
+import i18n from '../../i18n';
+
+const SeedButton = ({ round, tournament, user }) => {
+       const [showDialog, setShowDialog] = useState(false);
+
+       if (round.seed) {
+               return (
+                       <Button href={round.seed} target="_blank" variant="primary">
+                               {i18n.t('rounds.seed')}
+                       </Button>
+               );
+       }
+       if (maySetSeed(user, tournament)) {
+               return <>
+                       <SeedDialog
+                               onHide={() => setShowDialog(false)}
+                               round={round}
+                               show={showDialog}
+                       />
+                       <Button onClick={() => setShowDialog(true)} variant="outline-primary">
+                               {i18n.t('rounds.setSeed')}
+                       </Button>
+               </>;
+       }
+       return i18n.t('rounds.noSeed');
+};
+
+SeedButton.propTypes = {
+       round: PropTypes.shape({
+               seed: PropTypes.string,
+       }),
+       tournament: PropTypes.shape({
+       }),
+       user: PropTypes.shape({
+       }),
+};
+
+export default withTranslation()(withUser(SeedButton));