import { sortByFinished, sortByResult } from '../../helpers/Participant';
import { maySeeResults } from '../../helpers/permissions';
import { getRunners } from '../../helpers/Tournament';
+import { compareResult } from '../../helpers/Result';
import { withUser } from '../../helpers/UserContext';
const List = ({ round, tournament, user }) => {
if (tournament.type === 'open-async') {
- const results = round.results || [];
+ const results = maySeeResults(user, tournament, round)
+ ? (round.results || []).sort(compareResult)
+ : round.results || [];
return <div className="results d-flex flex-wrap">
{results.map(result =>
<Item
isTournamentCrew,
isTournamentMonitor,
patchUser,
+ sortByFinished,
sortByResult,
+ sortByUsername,
};
import React from 'react';
import Icon from '../components/common/Icon';
+export const compareResult = (a, b) => {
+ const a_placement = a && a.placement ? a.placement : 0;
+ const b_placement = b && b.placement ? b.placement : 0;
+ if (a_placement) {
+ if (b_placement) {
+ if (a_placement < b_placement) return -1;
+ if (b_placement < a_placement) return 1;
+ return compareUsername(a, b);
+ }
+ return -1;
+ }
+ if (b_placement) {
+ return 1;
+ }
+ return compareUsername(a, b);
+};
+
+export const compareUsername = (a, b) => {
+ const a_name = (a && a.user && a.user.username) || '';
+ const b_name = (b && b.user && b.user.username) || '';
+ return a_name.localeCompare(b_name);
+};
+
export const formatTime = result => {
const hours = `${Math.floor(result.time / 60 / 60)}`;
let minutes = `${Math.floor((result.time / 60) % 60)}`;
};
export default {
+ compareResult,
+ compareUsername,
formatTime,
getIcon,
getTime,
+export const compareFinished = round => (a, b) => {
+ const a_result = findResult(a, round);
+ const b_result = findResult(b, round);
+ const a_finished = a_result && a_result.has_finished;
+ const b_finished = b_result && b_result.has_finished;
+ if (a_finished) {
+ if (b_finished) {
+ return compareUsername(a, b);
+ }
+ return -1;
+ }
+ if (b_finished) {
+ return 1;
+ }
+ return compareUsername(a, b);
+};
+
+export const compareResult = round => (a, b) => {
+ const a_result = findResult(a, round);
+ const b_result = findResult(b, round);
+ const a_placement = a_result && a_result.placement ? a_result.placement : 0;
+ const b_placement = b_result && b_result.placement ? b_result.placement : 0;
+ if (a_placement) {
+ if (b_placement) {
+ if (a_placement < b_placement) return -1;
+ if (b_placement < a_placement) return 1;
+ return compareUsername(a, b);
+ }
+ return -1;
+ }
+ if (b_placement) {
+ return 1;
+ }
+ 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;
};
export default {
+ compareFinished,
+ compareResult,
+ compareUsername,
findResult,
getAvatarUrl,
getUserName,