import Loading from '../common/Loading';
import NotFound from '../pages/NotFound';
import Detail from '../tournament/Detail';
-import { patchResult } from '../../helpers/Tournament';
+import { patchResult, sortParticipants } from '../../helpers/Tournament';
const Tournament = () => {
const params = useParams();
.then(response => {
setError(null);
setLoading(false);
- setTournament(response.data);
+ setTournament(sortParticipants(response.data));
})
.catch(error => {
setError(error);
import PropTypes from 'prop-types';
import React from 'react';
+import { Button } from 'react-bootstrap';
import { withTranslation } from 'react-i18next';
import List from '../results/List';
<li className="round d-flex">
<div className="info">
<p className="date">{i18n.t('rounds.date', { date: new Date(round.created_at) })}</p>
+ {round.seed ?
+ <p className="seed">
+ <Button href={round.seed} target="_blank" variant="primary">
+ {i18n.t('rounds.seed')}
+ </Button>
+ </p>
+ : null}
{isParticipant(user, tournament) ?
- <ReportButton
- participant={findParticipant(tournament, user)}
- round={round}
- tournament={tournament}
- />
+ <p className="report">
+ <ReportButton
+ participant={findParticipant(tournament, user)}
+ round={round}
+ tournament={tournament}
+ />
+ </p>
: null}
</div>
<List round={round} tournament={tournament} />
Item.propTypes = {
round: PropTypes.shape({
created_at: PropTypes.string,
+ seed: PropTypes.string,
}),
tournament: PropTypes.shape({
participants: PropTypes.arrayOf(PropTypes.shape({
+export const compareUsername = (a, b) => {
+ const a_name = a && a.user && a.user.username ? a.user.username : '';
+ const b_name = b && b.user && b.user.username ? b.user.username : '';
+ return a_name.localeCompare(b_name);
+};
+
export const findResult = (participant, round) => {
if (!participant || !participant.user_id) return null;
if (!round || !round.results || !round.results.length) return null;
};
export default {
+ compareUsername,
findResult,
};
+import Participant from './Participant';
import Round from './Round';
export const findParticipant = (tournament, user) => {
};
};
+export const sortParticipants = tournament => {
+ if (!tournament || !tournament.participants || !tournament.participants.length) {
+ return tournament;
+ }
+ return {
+ ...tournament,
+ participants: tournament.participants.sort(Participant.compareUsername),
+ };
+};
+
export default {
findParticipant,
patchResult,
+ sortParticipants,
};
},
icon: {
DiscordIcon: 'Discord',
+ EditIcon: 'Bearbeiten',
+ FinishedIcon: 'Abgeschlossen',
LogoutIcon: 'Logout',
+ PendingIcon: 'Ausstehend',
},
participants: {
empty: 'Noch keine Teilnehmer eingetragen',
empty: 'Noch keine Runde gestartet',
heading: 'Runden',
new: 'Neue Runde',
+ seed: 'Seed',
},
validation: {
error: {