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" />;
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({
participants: PropTypes.arrayOf(PropTypes.shape({
})),
}),
+ user: PropTypes.shape({
+ }),
};
-export default List;
+export default withUser(List);
+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;
};
};
+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,