]> git.localhorst.tv Git - alttp.git/commitdiff
hide round placement
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 29 Mar 2022 21:31:50 +0000 (23:31 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 29 Mar 2022 21:31:50 +0000 (23:31 +0200)
resources/js/components/results/Item.js
resources/js/components/results/List.js
resources/js/helpers/Participant.js

index 0781ccaaa5b062b1f3993993349041d80d91ef9b..0d73105edd21ac13268223742196ca9bbdfe3daa 100644 (file)
@@ -16,13 +16,13 @@ const getIcon = (result, maySee) => {
        if (result.forfeit && maySee) {
                return <Icon.FORFEIT className="text-danger" size="lg" />;
        }
-       if (result.placement === 1) {
+       if (result.placement === 1 && maySee) {
                return <Icon.FIRST_PLACE className="text-gold" size="lg" />;
        }
-       if (result.placement === 2) {
+       if (result.placement === 2 && maySee) {
                return <Icon.SECOND_PLACE className="text-silver" size="lg" />;
        }
-       if (result.placement === 3) {
+       if (result.placement === 3 && maySee) {
                return <Icon.THIRD_PLACE className="text-bronze" size="lg" />;
        }
        return <Icon.FINISHED className="text-success" size="lg" />;
index f4d4ff10ee502130f44f65a9e03762347100d692..14c70968cd5324823c558732df049e3a2fd715ea 100644 (file)
@@ -2,19 +2,26 @@ import PropTypes from 'prop-types';
 import React from 'react';
 
 import Item from './Item';
-import { sortByResult } from '../../helpers/Participant';
+import { sortByFinished, sortByResult } from '../../helpers/Participant';
+import { maySeeResults } from '../../helpers/permissions';
 import { getRunners } from '../../helpers/Tournament';
+import { withUser } from '../../helpers/UserContext';
 
-const List = ({ round, tournament }) => <div className="results d-flex flex-wrap">
-       {sortByResult(getRunners(tournament), round).map(participant =>
-               <Item
-                       key={participant.id}
-                       participant={participant}
-                       round={round}
-                       tournament={tournament}
-               />
-       )}
-</div>;
+const List = ({ round, tournament, user }) => {
+       const runners = maySeeResults(user, tournament, round)
+               ? sortByResult(getRunners(tournament), round)
+               : sortByFinished(getRunners(tournament), round);
+       return <div className="results d-flex flex-wrap">
+               {runners.map(participant =>
+                       <Item
+                               key={participant.id}
+                               participant={participant}
+                               round={round}
+                               tournament={tournament}
+                       />
+               )}
+       </div>;
+};
 
 List.propTypes = {
        round: PropTypes.shape({
@@ -23,6 +30,8 @@ List.propTypes = {
                participants: PropTypes.arrayOf(PropTypes.shape({
                })),
        }),
+       user: PropTypes.shape({
+       }),
 };
 
-export default List;
+export default withUser(List);
index 4b4b6ef51c5ee0cb72a73b9ddaca50e2d2321e1a..7a689960ea831945428edb9aed1aa43cb3f889a4 100644 (file)
@@ -1,3 +1,20 @@
+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 comparePlacement = (a, b) => {
        if (a.placement < b.placement) return -1;
        if (b.placement < a.placement) return 1;
@@ -59,13 +76,26 @@ export const patchUser = (participant, user) => {
        };
 };
 
+export const sortByFinished = (participants, round) => {
+       if (!participants || !participants.length) return participants;
+       if (!round || !round.results || !round.results.length) return participants;
+       return participants.sort(compareFinished(round));
+};
+
 export const sortByResult = (participants, round) => {
        if (!participants || !participants.length) return participants;
        if (!round || !round.results || !round.results.length) return participants;
        return participants.sort(compareResult(round));
 };
 
+export const sortByUsername = (participants, round) => {
+       if (!participants || !participants.length) return participants;
+       if (!round || !round.results || !round.results.length) return participants;
+       return participants.sort(compareUsername);
+};
+
 export default {
+       compareFinished,
        compareResult,
        compareUsername,
        findResult,