]> git.localhorst.tv Git - alttp.git/blob - resources/js/helpers/Tournament.js
add seed display
[alttp.git] / resources / js / helpers / Tournament.js
1 import Participant from './Participant';
2 import Round from './Round';
3
4 export const findParticipant = (tournament, user) => {
5         if (!tournament || !tournament.participants || !tournament.participants.length) return null;
6         if (!user || !user.id) return null;
7         return tournament.participants.find(p => p.user_id == user.id);
8 };
9
10 export const patchResult = (tournament, result) => {
11         if (!tournament || !tournament.rounds) return tournament;
12         return {
13                 ...tournament,
14                 rounds: tournament.rounds.map(round =>
15                         round.id === result.round_id
16                                 ? Round.patchResult(round, result)
17                                 : round
18                 ),
19         };
20 };
21
22 export const sortParticipants = tournament => {
23         if (!tournament || !tournament.participants || !tournament.participants.length) {
24                 return tournament;
25         }
26         return {
27                 ...tournament,
28                 participants: tournament.participants.sort(Participant.compareUsername),
29         };
30 };
31
32 export default {
33         findParticipant,
34         patchResult,
35         sortParticipants,
36 };