]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/helpers/Tournament.js
sort results by time
[alttp.git] / resources / js / helpers / Tournament.js
index 1b808fdf3211f8eede21ee009defb1043db3d4d6..6b4ca28fb93c2c185ec096ed4579707a93f52ead 100644 (file)
@@ -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,
 };