X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fhelpers%2FTournament.js;h=6b4ca28fb93c2c185ec096ed4579707a93f52ead;hb=14bee4bbb112ddab53914fa777be6004debeb5c4;hp=1b808fdf3211f8eede21ee009defb1043db3d4d6;hpb=d748feb96453d74aeffec648d6f5f68d9ef3b520;p=alttp.git diff --git a/resources/js/helpers/Tournament.js b/resources/js/helpers/Tournament.js index 1b808fd..6b4ca28 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,26 @@ export const patchResult = (tournament, result) => { }; }; +export const patchRound = (tournament, round) => { + if (!tournament) return tournament; + return { + ...tournament, + rounds: tournament.rounds.map(r => r.id === round.id ? round : r), + }; +}; + +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, };