From: Daniel Karbach Date: Sat, 12 Mar 2022 12:36:31 +0000 (+0100) Subject: add seed display X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=ccaa2cf99468fea81efdf28aaa3fc72a278a95f6;p=alttp.git add seed display --- diff --git a/resources/js/components/pages/Tournament.js b/resources/js/components/pages/Tournament.js index 64c8906..aab4423 100644 --- a/resources/js/components/pages/Tournament.js +++ b/resources/js/components/pages/Tournament.js @@ -7,7 +7,7 @@ import ErrorMessage from '../common/ErrorMessage'; 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(); @@ -24,7 +24,7 @@ const Tournament = () => { .then(response => { setError(null); setLoading(false); - setTournament(response.data); + setTournament(sortParticipants(response.data)); }) .catch(error => { setError(error); diff --git a/resources/js/components/rounds/Item.js b/resources/js/components/rounds/Item.js index c4e3374..b227e93 100644 --- a/resources/js/components/rounds/Item.js +++ b/resources/js/components/rounds/Item.js @@ -1,5 +1,6 @@ import PropTypes from 'prop-types'; import React from 'react'; +import { Button } from 'react-bootstrap'; import { withTranslation } from 'react-i18next'; import List from '../results/List'; @@ -17,12 +18,21 @@ const Item = ({
  • {i18n.t('rounds.date', { date: new Date(round.created_at) })}

    + {round.seed ? +

    + +

    + : null} {isParticipant(user, tournament) ? - +

    + +

    : null}
    @@ -31,6 +41,7 @@ const Item = ({ Item.propTypes = { round: PropTypes.shape({ created_at: PropTypes.string, + seed: PropTypes.string, }), tournament: PropTypes.shape({ participants: PropTypes.arrayOf(PropTypes.shape({ diff --git a/resources/js/helpers/Participant.js b/resources/js/helpers/Participant.js index af6eecc..8ae225c 100644 --- a/resources/js/helpers/Participant.js +++ b/resources/js/helpers/Participant.js @@ -1,3 +1,9 @@ +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; @@ -5,5 +11,6 @@ export const findResult = (participant, round) => { }; export default { + compareUsername, findResult, }; diff --git a/resources/js/helpers/Tournament.js b/resources/js/helpers/Tournament.js index 1b808fd..5716e68 100644 --- a/resources/js/helpers/Tournament.js +++ b/resources/js/helpers/Tournament.js @@ -1,3 +1,4 @@ +import Participant from './Participant'; import Round from './Round'; export const findParticipant = (tournament, user) => { @@ -18,7 +19,18 @@ export const patchResult = (tournament, result) => { }; }; +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, }; diff --git a/resources/js/i18n/de.js b/resources/js/i18n/de.js index 3a2804c..c978ca4 100644 --- a/resources/js/i18n/de.js +++ b/resources/js/i18n/de.js @@ -20,7 +20,10 @@ export default { }, icon: { DiscordIcon: 'Discord', + EditIcon: 'Bearbeiten', + FinishedIcon: 'Abgeschlossen', LogoutIcon: 'Logout', + PendingIcon: 'Ausstehend', }, participants: { empty: 'Noch keine Teilnehmer eingetragen', @@ -48,6 +51,7 @@ export default { empty: 'Noch keine Runde gestartet', heading: 'Runden', new: 'Neue Runde', + seed: 'Seed', }, validation: { error: {