]> git.localhorst.tv Git - alttp.git/commitdiff
fix some result display issues
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 7 May 2025 14:13:45 +0000 (16:13 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 7 May 2025 14:13:45 +0000 (16:13 +0200)
app/Policies/RoundPolicy.php
resources/js/components/results/List.js
resources/js/helpers/Result.js
resources/js/helpers/permissions.js

index 5bb46c073b69f97abd40515640e9c465d3827123..645a03fe6767bc9490cbce2aa548fd7a7ff28895 100644 (file)
@@ -101,6 +101,9 @@ class RoundPolicy
         */
        public function seeResults(?User $user, Round $round)
        {
+               if ($round->tournament->result_reveal == 'always') {
+                       return true;
+               }
                if (
                        $round->locked ||
                        ($user && $user->isTournamentMonitor($round->tournament)) ||
index 911b6a53ba5526a70cb9073963190e6d0883949e..f26a1310a3d48271b6caef2e8b5a6fa6166b77ba 100644 (file)
@@ -5,7 +5,7 @@ import Item from './Item';
 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 }) => {
@@ -13,8 +13,8 @@ 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
index 329116d245515ffa0f3603d599a620388443156e..1215d713e2680dcb48c18804b3533605d1da6f40 100644 (file)
@@ -1,6 +1,12 @@
 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;
@@ -18,12 +24,6 @@ export const compareResult = (a, b) => {
        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)}`;
@@ -74,6 +74,10 @@ export const parseTime = str => {
        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,
index c24d75a97eafebb0eebfa80b42fb8cac2b4e693f..c406cd99444ebd5d515c4f060ac83c70e003b9d3 100644 (file)
@@ -152,6 +152,9 @@ export const mayViewProtocol = (user, tournament) =>
        isTournamentCrew(user, tournament);
 
 export const maySeeResults = (user, tournament, round) => {
+       if (tournament.result_reveal === 'always') {
+               return true;
+       }
        if (
                round.locked ||
                isTournamentMonitor(user, tournament) ||