From: Daniel Karbach Date: Tue, 29 Mar 2022 21:31:50 +0000 (+0200) Subject: hide round placement X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;h=855decfd62b51ed500c8a5903f4b263c4c9afb5c;hp=a748d5724c8acff6e3bb3fe6c20aa5968b65d58a;p=alttp.git hide round placement --- diff --git a/resources/js/components/results/Item.js b/resources/js/components/results/Item.js index 0781cca..0d73105 100644 --- a/resources/js/components/results/Item.js +++ b/resources/js/components/results/Item.js @@ -16,13 +16,13 @@ const getIcon = (result, maySee) => { if (result.forfeit && maySee) { return ; } - if (result.placement === 1) { + if (result.placement === 1 && maySee) { return ; } - if (result.placement === 2) { + if (result.placement === 2 && maySee) { return ; } - if (result.placement === 3) { + if (result.placement === 3 && maySee) { return ; } return ; diff --git a/resources/js/components/results/List.js b/resources/js/components/results/List.js index f4d4ff1..14c7096 100644 --- a/resources/js/components/results/List.js +++ b/resources/js/components/results/List.js @@ -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 }) =>
- {sortByResult(getRunners(tournament), round).map(participant => - - )} -
; +const List = ({ round, tournament, user }) => { + const runners = maySeeResults(user, tournament, round) + ? sortByResult(getRunners(tournament), round) + : sortByFinished(getRunners(tournament), round); + return
+ {runners.map(participant => + + )} +
; +}; 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); diff --git a/resources/js/helpers/Participant.js b/resources/js/helpers/Participant.js index 4b4b6ef..7a68996 100644 --- a/resources/js/helpers/Participant.js +++ b/resources/js/helpers/Participant.js @@ -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,