]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/rounds/LockButton.js
improved user context
[alttp.git] / resources / js / components / rounds / LockButton.js
index 38411ebb0b1b83d27c13f9927fdb21943fe33b1e..c29b3d3f7412ecd8b53ca9add6695289e06026ef 100644 (file)
@@ -1,26 +1,27 @@
 import PropTypes from 'prop-types';
 import React, { useState } from 'react';
 import { Button } from 'react-bootstrap';
-import { withTranslation } from 'react-i18next';
+import { useTranslation } from 'react-i18next';
 
 import LockDialog from './LockDialog';
 import Icon from '../common/Icon';
 import { mayLockRound } from '../../helpers/permissions';
-import { withUser } from '../../helpers/UserContext';
-import i18n from '../../i18n';
+import { useUser } from '../../hooks/user';
 
 const LockButton = ({
        round,
        tournament,
-       user,
 }) => {
        const [showDialog, setShowDialog] = useState(false);
 
+       const { t } = useTranslation();
+       const { user } = useUser();
+
        if (!mayLockRound(user, tournament, round)) {
                if (round.locked) {
-                       return <Icon.LOCKED title={i18n.t('rounds.locked')} />;
+                       return <Icon.LOCKED title={t('rounds.locked')} />;
                } else {
-                       return <Icon.UNLOCKED title={i18n.t('rounds.unlocked')} />;
+                       return <Icon.UNLOCKED title={t('rounds.unlocked')} />;
                }
        }
 
@@ -34,7 +35,7 @@ const LockButton = ({
                <Button
                        onClick={() => setShowDialog(true)}
                        size="sm"
-                       title={round.locked ? i18n.t('rounds.locked') : i18n.t('rounds.unlocked') }
+                       title={t(round.locked ? 'rounds.locked' : 'rounds.unlocked')}
                        variant="outline-secondary"
                >
                        {round.locked ?
@@ -52,8 +53,6 @@ LockButton.propTypes = {
        }),
        tournament: PropTypes.shape({
        }),
-       user: PropTypes.shape({
-       }),
 };
 
-export default withTranslation()(withUser(LockButton));
+export default LockButton;