-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);
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) {
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;