X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fhelpers%2FParticipant.js;h=eb943401f6074057b4e6fc625c0d7385c4d15042;hb=beccf752aafd468c3753c6d48ae30bccd946c3b9;hp=e5a135f1b14c47f09182898f0d92aa8aaf5cfa13;hpb=14bee4bbb112ddab53914fa777be6004debeb5c4;p=alttp.git diff --git a/resources/js/helpers/Participant.js b/resources/js/helpers/Participant.js index e5a135f..eb94340 100644 --- a/resources/js/helpers/Participant.js +++ b/resources/js/helpers/Participant.js @@ -1,8 +1,8 @@ export const compareResult = round => (a, b) => { const a_result = findResult(a, round); const b_result = findResult(b, round); - const a_time = a_result ? a_result.time : 0; - const b_time = b_result ? b_result.time : 0; + const a_time = a_result && !a_result.forfeit ? a_result.time : 0; + const b_time = b_result && !b_result.forfeit ? b_result.time : 0; if (a_time) { if (b_time) { if (a_time < b_time) return -1; @@ -14,7 +14,18 @@ export const compareResult = round => (a, b) => { if (b_time) { return 1; } - return 0; + const a_forfeit = a_result && a_result.forfeit; + const b_forfeit = b_result && b_result.forfeit; + if (a_forfeit) { + if (b_forfeit) { + return 0; + } + return -1; + } + if (b_forfeit) { + return 1; + } + return compareUsername(a, b); }; export const compareUsername = (a, b) => { @@ -29,6 +40,18 @@ export const findResult = (participant, round) => { return round.results.find(result => result.user_id === participant.user_id); }; +export const patchUser = (participant, user) => { + if (!participant || !user) return participant; + if (participant.user_id != user.id) return participant; + return { + ...participant, + user: { + ...participant.user, + ...user, + }, + }; +}; + export const sortByResult = (participants, round) => { if (!participants || !participants.length) return participants; if (!round || !round.results || !round.results.length) return participants; @@ -39,5 +62,6 @@ export default { compareResult, compareUsername, findResult, + patchUser, sortByResult, };