import { sortByFinished, sortByResult } from '../../helpers/Participant';
import { maySeeResults } from '../../helpers/permissions';
import { getRunners } from '../../helpers/Tournament';
-import { compareResult } from '../../helpers/Result';
+import { sortByTime, sortByUsername } from '../../helpers/Result';
import { useUser } from '../../hooks/user';
const List = ({ round, tournament }) => {
if (tournament.type === 'open-async') {
const results = maySeeResults(user, tournament, round)
- ? (round.results || []).sort(compareResult)
- : round.results || [];
+ ? sortByTime(round.results || [])
+ : sortByUsername(round.results || []);
return <div className="results d-flex flex-wrap">
{results.map(result =>
<Item
import React from 'react';
import Icon from '../components/common/Icon';
+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 compareResult = (a, b) => {
const a_placement = a && a.placement ? a.placement : 0;
const b_placement = b && b.placement ? b.placement : 0;
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)}`;
return `${str}`.trim().split(/[-.: ]+/).reduce((acc,time) => (60 * acc) + +time, 0);
};
+export const sortByTime = (results) => [...results].sort(compareResult);
+
+export const sortByUsername = (results) => [...results].sort(compareUsername);
+
export default {
compareResult,
compareUsername,
isTournamentCrew(user, tournament);
export const maySeeResults = (user, tournament, round) => {
+ if (tournament.result_reveal === 'always') {
+ return true;
+ }
if (
round.locked ||
isTournamentMonitor(user, tournament) ||