1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { withTranslation } from 'react-i18next';
5 import Icon from '../common/Icon';
6 import Box from '../users/Box';
7 import { formatTime } from '../../helpers/Result';
8 import { findResult } from '../../helpers/Participant';
9 import { maySeeResults } from '../../helpers/permissions';
10 import { withUser } from '../../helpers/UserContext';
12 const getIcon = (result, maySee) => {
13 if (!result || !result.has_finished) {
14 return <Icon.PENDING className="text-muted" size="lg" />;
16 if (result.forfeit && maySee) {
17 return <Icon.FORFEIT className="text-danger" size="lg" />;
19 if (result.placement === 1 && maySee) {
20 return <Icon.FIRST_PLACE className="text-gold" size="lg" />;
22 if (result.placement === 2 && maySee) {
23 return <Icon.SECOND_PLACE className="text-silver" size="lg" />;
25 if (result.placement === 3 && maySee) {
26 return <Icon.THIRD_PLACE className="text-bronze" size="lg" />;
28 return <Icon.FINISHED className="text-success" size="lg" />;
31 const getTime = (result, maySee) => {
32 if (!result || !maySee) {
36 return formatTime(result);
44 const getClassName = result => {
45 const classNames = ['status'];
46 if (result && result.has_finished) {
47 classNames.push('finished');
49 classNames.push('has-comment');
52 classNames.push('pending');
54 return classNames.join(' ');
63 const result = findResult(participant, round);
64 const maySee = maySeeResults(user, tournament, round);
65 return <div className="result">
66 <Box user={participant.user} />
68 className={getClassName(result)}
69 title={maySee && result && result.comment ? result.comment : null}
71 <span className="time">
72 {getTime(result, maySee)}
74 {getIcon(result, maySee)}
80 participant: PropTypes.shape({
81 user: PropTypes.shape({
84 round: PropTypes.shape({
86 tournament: PropTypes.shape({
88 user: PropTypes.shape({
92 export default withTranslation()(withUser(Item));