1 export const compareFinished = round => (a, b) => {
2 const a_result = findResult(a, round);
3 const b_result = findResult(b, round);
4 const a_finished = a_result && a_result.has_finished;
5 const b_finished = b_result && b_result.has_finished;
8 return compareUsername(a, b);
15 return compareUsername(a, b);
18 export const compareResult = round => (a, b) => {
19 const a_result = findResult(a, round);
20 const b_result = findResult(b, round);
21 const a_placement = a_result && a_result.placement ? a_result.placement : 0;
22 const b_placement = b_result && b_result.placement ? b_result.placement : 0;
25 if (a_placement < b_placement) return -1;
26 if (b_placement < a_placement) return 1;
27 return compareUsername(a, b);
34 return compareUsername(a, b);
37 export const compareUsername = (a, b) => {
38 const a_name = getUserName(a);
39 const b_name = getUserName(b);
40 return a_name.localeCompare(b_name);
43 export const findResult = (user, round) => {
44 if (!user || !user.id) return null;
45 if (!round || !round.results || !round.results.length) return null;
46 return round.results.find(result => result.user_id == user.id);
49 export const getAvatarUrl = user => {
50 if (user && user.avatar) {
51 if (user.avatar_cached) {
52 return `/media/avatar/${user.id}/${user.avatar}.png`;
54 return `//cdn.discordapp.com/avatars/${user.id}/${user.avatar}.png`;
56 return '/default-avatar.png';
59 export const getUserName = user => (user &&
60 (user.nickname || user.discord_nickname || user.username)) || '';
62 export const hasFinishedRound = (user, round) => {
63 const result = findResult(user, round);
64 return result && result.has_finished;