X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fhelpers%2FCrew.js;h=205c0e8b5ebd1786dc24fcc0a314b3745a2514e8;hb=249e06be11d0f7778d99956c87d4f0a8ac7e69f7;hp=e60210fd799d8f28b85d44c0947da4c74d103499;hpb=e2af94795e9d8e8a2eb8c272201b4e54ebb130f0;p=alttp.git diff --git a/resources/js/helpers/Crew.js b/resources/js/helpers/Crew.js index e60210f..205c0e8 100644 --- a/resources/js/helpers/Crew.js +++ b/resources/js/helpers/Crew.js @@ -1,12 +1,29 @@ export const compareCrew = (a, b) => { + return compareCrewConfirmed(a, b) || compareCrewChannel(a, b) || compareCrewName(a, b); +}; + +export const compareCrewChannel = (a, b) => { + const a_channel = (a && a.channel_id) || null; + const b_channel = (b && b.channel_id) || null; + if (a_channel === b_channel) return 0; + if (!a_channel) return -1; + if (!b_channel) return 1; + return a_channel - b_channel; +}; + +export const compareCrewConfirmed = (a, b) => { const a_confirmed = !!(a && a.confirmed); const b_confirmed = !!(b && b.confirmed); if (a_confirmed === b_confirmed) { - return getName(a).localeCompare(getName(b)); + return 0; } return a_confirmed ? -1 : 1; }; +export const compareCrewName = (a, b) => { + return getName(a).localeCompare(getName(b)); +}; + export const getName = crew => { if (!crew) return ''; if (crew.name_override) {