]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/helpers/Participant.js
tracker layout
[alttp.git] / resources / js / helpers / Participant.js
index 7a689960ea831945428edb9aed1aa43cb3f889a4..1a24f8efef9ee242be68ec7e0af9a271fda6010a 100644 (file)
@@ -1,3 +1,5 @@
+import User from './User';
+
 export const compareFinished = round => (a, b) => {
        const a_result = findResult(a, round);
        const b_result = findResult(b, round);
@@ -41,8 +43,8 @@ export const compareResult = round => (a, b) => {
 };
 
 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 : '';
+       const a_name = getUserName(a);
+       const b_name = getUserName(b);
        return a_name.localeCompare(b_name);
 };
 
@@ -52,6 +54,9 @@ export const findResult = (participant, round) => {
        return round.results.find(result => result.user_id === participant.user_id);
 };
 
+export const getUserName = participant =>
+       participant.user ? User.getUserName(participant.user) : '';
+
 export const isRunner = participant =>
        participant && participant.roles && participant.roles.includes('runner');
 
@@ -99,10 +104,13 @@ export default {
        compareResult,
        compareUsername,
        findResult,
+       getUserName,
        isRunner,
        isTournamentAdmin,
        isTournamentCrew,
        isTournamentMonitor,
        patchUser,
+       sortByFinished,
        sortByResult,
+       sortByUsername,
 };