X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fhelpers%2FUser.js;h=b00c853542d6eb739ec6fec3cec8f0771473ae49;hb=8645b77ea2dc402f0265e1c8022ba18302506ca1;hp=9a554449cdfb0dd437c10c13ab6e344273c3d70e;hpb=35dca1d496a5298daad2fc5f926a9fe400f68dce;p=alttp.git diff --git a/resources/js/helpers/User.js b/resources/js/helpers/User.js index 9a55444..b00c853 100644 --- a/resources/js/helpers/User.js +++ b/resources/js/helpers/User.js @@ -1,4 +1,17 @@ -import moment from 'moment'; +export const getUserName = user => (user && + (user.nickname || user.discord_nickname || user.username)) || ''; + +export const compareUsername = (a, b) => { + const a_name = getUserName(a); + const b_name = getUserName(b); + return a_name.localeCompare(b_name); +}; + +export const findResult = (user, round) => { + if (!user || !user.id) return null; + if (!round || !round.results || !round.results.length) return null; + return round.results.find(result => result.user_id == user.id); +}; export const compareFinished = round => (a, b) => { const a_result = findResult(a, round); @@ -36,18 +49,6 @@ export const compareResult = round => (a, b) => { return compareUsername(a, b); }; -export const compareUsername = (a, b) => { - const a_name = getUserName(a); - const b_name = getUserName(b); - return a_name.localeCompare(b_name); -}; - -export const findResult = (user, round) => { - if (!user || !user.id) return null; - if (!round || !round.results || !round.results.length) return null; - return round.results.find(result => result.user_id == user.id); -}; - export const getAvatarUrl = user => { if (user && user.avatar) { if (user.avatar_cached) { @@ -58,8 +59,6 @@ export const getAvatarUrl = user => { return '/default-avatar.png'; }; -export const getUserName = user => (user && (user.nickname || user.username)) || ''; - export const hasFinishedRound = (user, round) => { const result = findResult(user, round); return result && result.has_finished;