]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/components/tournament/Detail.js
improved user context
[alttp.git] / resources / js / components / tournament / Detail.js
index bb9b9284461ebe85ea7c4a818cb417c8c7df43f6..84592f6beb1a525a5f2886cf6661600ad2c975ec 100644 (file)
@@ -1,7 +1,7 @@
 import PropTypes from 'prop-types';
 import React from 'react';
 import { Button, Col, Container, Row } from 'react-bootstrap';
-import { withTranslation } from 'react-i18next';
+import { useTranslation } from 'react-i18next';
 
 import ApplyButton from './ApplyButton';
 import Scoreboard from './Scoreboard';
@@ -25,8 +25,7 @@ import {
        hasTournamentAdmins,
        hasTournamentMonitors,
 } from '../../helpers/Tournament';
-import { withUser } from '../../helpers/UserContext';
-import i18n from '../../i18n';
+import { useUser } from '../../hooks/user';
 
 const getClassName = (tournament, user) => {
        const classNames = ['tournament'];
@@ -44,76 +43,80 @@ const getClassName = (tournament, user) => {
 const Detail = ({
        addRound,
        tournament,
-       user,
-}) => <Container className={getClassName(tournament, user)} fluid>
-       <Row>
-               <Col lg={8} xl={9}>
-                       <div className="d-flex align-items-center justify-content-between">
-                               <h1>{tournament.title}</h1>
-                               <div className="button-bar">
-                                       <ApplicationsButton tournament={tournament} />
-                                       <ApplyButton tournament={tournament} />
-                                       {mayUpdateTournament(user, tournament) ?
-                                               <SettingsButton tournament={tournament} />
-                                       : null}
-                                       {mayViewProtocol(user, tournament) ?
-                                               <Protocol id={tournament.id} />
-                                       : null}
-                               </div>
-                       </div>
-               </Col>
-       </Row>
-       <Row>
-               <Col lg={{ order: 2, span: 4 }} xl={{ order: 2, span: 3 }}>
-                       <div className="tournament-sidebar">
-                               {hasScoreboard(tournament) ? <>
-                                       <div className="d-flex align-items-center justify-content-between">
-                                               <h2>{i18n.t('tournaments.scoreboard')}</h2>
-                                               {hasRunners(tournament) && tournament.rounds.length > 2 ?
-                                                       <ScoreChartButton tournament={tournament} />
+}) => {
+       const { t } = useTranslation();
+       const { user } = useUser();
+
+       return <Container className={getClassName(tournament, user)} fluid>
+               <Row>
+                       <Col lg={8} xl={9}>
+                               <div className="d-flex align-items-center justify-content-between">
+                                       <h1>{tournament.title}</h1>
+                                       <div className="button-bar">
+                                               <ApplicationsButton tournament={tournament} />
+                                               <ApplyButton tournament={tournament} />
+                                               {mayUpdateTournament(user, tournament) ?
+                                                       <SettingsButton tournament={tournament} />
+                                               : null}
+                                               {mayViewProtocol(user, tournament) ?
+                                                       <Protocol id={tournament.id} />
                                                : null}
                                        </div>
-                                       {hasRunners(tournament) ?
-                                               <Scoreboard tournament={tournament} />
-                                       : null}
-                               </> : null}
-                               {hasTournamentAdmins(tournament) ?
-                                       <>
-                                               <div className="d-flex align-items-center justify-content-between">
-                                                       <h2>{i18n.t('tournaments.admins')}</h2>
-                                               </div>
-                                               {getTournamentAdmins(tournament).map(p =>
-                                                       <p key={p.id}><Box user={p.user} /></p>
-                                               )}
-                                       </>
-                               : null}
-                               {hasTournamentMonitors(tournament) ?
-                                       <>
+                               </div>
+                       </Col>
+               </Row>
+               <Row>
+                       <Col lg={{ order: 2, span: 4 }} xl={{ order: 2, span: 3 }}>
+                               <div className="tournament-sidebar">
+                                       {hasScoreboard(tournament) ? <>
                                                <div className="d-flex align-items-center justify-content-between">
-                                                       <h2>{i18n.t('tournaments.monitors')}</h2>
+                                                       <h2>{t('tournaments.scoreboard')}</h2>
+                                                       {hasRunners(tournament) && tournament.rounds.length > 2 ?
+                                                               <ScoreChartButton tournament={tournament} />
+                                                       : null}
                                                </div>
-                                               {getTournamentMonitors(tournament).map(p =>
-                                                       <p key={p.id}><Box user={p.user} /></p>
-                                               )}
-                                       </>
-                               : null}
-                       </div>
-               </Col>
-               <Col lg={{ order: 1, span: 8 }} xl={{ order: 1, span: 9 }}>
-                       <div className="d-flex align-items-center justify-content-between">
-                               <h2>{i18n.t('rounds.heading')}</h2>
-                               {addRound && mayAddRounds(user, tournament) ?
-                                       <Button onClick={addRound}>
-                                               {i18n.t('rounds.new')}
-                                       </Button>
+                                               {hasRunners(tournament) ?
+                                                       <Scoreboard tournament={tournament} />
+                                               : null}
+                                       </> : null}
+                                       {hasTournamentAdmins(tournament) ?
+                                               <>
+                                                       <div className="d-flex align-items-center justify-content-between">
+                                                               <h2>{t('tournaments.admins')}</h2>
+                                                       </div>
+                                                       {getTournamentAdmins(tournament).map(p =>
+                                                               <p key={p.id}><Box user={p.user} /></p>
+                                                       )}
+                                               </>
+                                       : null}
+                                       {hasTournamentMonitors(tournament) ?
+                                               <>
+                                                       <div className="d-flex align-items-center justify-content-between">
+                                                               <h2>{t('tournaments.monitors')}</h2>
+                                                       </div>
+                                                       {getTournamentMonitors(tournament).map(p =>
+                                                               <p key={p.id}><Box user={p.user} /></p>
+                                                       )}
+                                               </>
+                                       : null}
+                               </div>
+                       </Col>
+                       <Col lg={{ order: 1, span: 8 }} xl={{ order: 1, span: 9 }}>
+                               <div className="d-flex align-items-center justify-content-between">
+                                       <h2>{t('rounds.heading')}</h2>
+                                       {addRound && mayAddRounds(user, tournament) ?
+                                               <Button onClick={addRound}>
+                                                       {t('rounds.new')}
+                                               </Button>
+                                       : null}
+                               </div>
+                               {tournament.rounds ?
+                                       <Rounds rounds={tournament.rounds} tournament={tournament} />
                                : null}
-                       </div>
-                       {tournament.rounds ?
-                               <Rounds rounds={tournament.rounds} tournament={tournament} />
-                       : null}
-               </Col>
-       </Row>
-</Container>;
+                       </Col>
+               </Row>
+       </Container>;
+};
 
 Detail.propTypes = {
        addRound: PropTypes.func,
@@ -125,8 +128,6 @@ Detail.propTypes = {
                })),
                title: PropTypes.string,
        }),
-       user: PropTypes.shape({
-       }),
 };
 
-export default withTranslation()(withUser(Detail));
+export default Detail;