]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/rounds/Item.js
improved user context
[alttp.git] / resources / js / components / rounds / Item.js
index 817069f98dc1fb7552188ed0cbfcb80a9d326dcd..949eeb2f2ec910e99b94ba9bf0a01c67a5549ba3 100644 (file)
@@ -1,6 +1,6 @@
 import PropTypes from 'prop-types';
 import React from 'react';
-import { withTranslation } from 'react-i18next';
+import { useTranslation } from 'react-i18next';
 
 import EditButton from './EditButton';
 import LockButton from './LockButton';
@@ -12,8 +12,7 @@ import ReportButton from '../results/ReportButton';
 import { mayEditRound, mayReportResult, isRunner } from '../../helpers/permissions';
 import { isComplete } from '../../helpers/Round';
 import { hasFinishedRound } from '../../helpers/User';
-import { withUser } from '../../helpers/UserContext';
-import i18n from '../../i18n';
+import { useUser } from '../../hooks/user';
 
 const getClassName = (round, tournament, user) => {
        const classNames = ['round'];
@@ -38,54 +37,57 @@ const getClassName = (round, tournament, user) => {
 const Item = ({
        round,
        tournament,
-       user,
-}) =>
-<li className={getClassName(round, tournament, user)}>
-       {round.title ?
-               <h3>{round.title}</h3>
-       : null}
-       <div className="d-flex">
-               <div className="info">
-                       <p className="date">
-                               {round.number ? `#${round.number} ` : '#?'}
-                               {i18n.t('rounds.date', { date: new Date(round.created_at) })}
-                       </p>
-                       <p className="seed">
-                               {round.code && round.code.length ?
-                                       <>
-                                               <SeedCode code={round.code} game={round.game || 'alttpr'} />
-                                               <br />
-                                       </>
-                               : null}
-                               <SeedButton
-                                       round={round}
-                                       tournament={tournament}
-                               />
-                               {' '}
-                               <SeedRolledBy round={round} />
-                       </p>
-                       {mayReportResult(user, tournament) ?
-                               <p className="report">
-                                       <ReportButton
+}) => {
+       const { t } = useTranslation();
+       const { user } = useUser();
+
+return <li className={getClassName(round, tournament, user)}>
+               {round.title ?
+                       <h3>{round.title}</h3>
+               : null}
+               <div className="d-flex">
+                       <div className="info">
+                               <p className="date">
+                                       {round.number ? `#${round.number} ` : '#?'}
+                                       {t('rounds.date', { date: new Date(round.created_at) })}
+                               </p>
+                               <p className="seed">
+                                       {round.code && round.code.length ?
+                                               <>
+                                                       <SeedCode code={round.code} game={round.game || 'alttpr'} />
+                                                       <br />
+                                               </>
+                                       : null}
+                                       <SeedButton
                                                round={round}
                                                tournament={tournament}
-                                               user={user}
                                        />
+                                       {' '}
+                                       <SeedRolledBy round={round} />
                                </p>
-                       : null}
-                       {tournament.type === 'open-async' && round.results && round.results.length ?
-                               <p>{i18n.t('rounds.numberOfResults', { count: round.results.length })}</p>
-                       : null}
-                       <div className="button-bar">
-                               <LockButton round={round} tournament={tournament} />
-                               {mayEditRound(user, tournament, round) ?
-                                       <EditButton round={round} tournament={tournament} />
+                               {mayReportResult(user, tournament) ?
+                                       <p className="report">
+                                               <ReportButton
+                                                       round={round}
+                                                       tournament={tournament}
+                                                       user={user}
+                                               />
+                                       </p>
                                : null}
+                               {tournament.type === 'open-async' && round.results && round.results.length ?
+                                       <p>{t('rounds.numberOfResults', { count: round.results.length })}</p>
+                               : null}
+                               <div className="button-bar">
+                                       <LockButton round={round} tournament={tournament} />
+                                       {mayEditRound(user, tournament, round) ?
+                                               <EditButton round={round} tournament={tournament} />
+                                       : null}
+                               </div>
                        </div>
+                       <List round={round} tournament={tournament} />
                </div>
-               <List round={round} tournament={tournament} />
-       </div>
-</li>;
+       </li>;
+};
 
 Item.propTypes = {
        round: PropTypes.shape({
@@ -104,8 +106,6 @@ Item.propTypes = {
                })),
                type: PropTypes.string,
        }),
-       user: PropTypes.shape({
-       }),
 };
 
-export default withTranslation()(withUser(Item));
+export default Item;