X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fcomponents%2Fresults%2FItem.js;h=0d73105edd21ac13268223742196ca9bbdfe3daa;hb=eca3f0074e6f9e882b91893e554ce249e25338de;hp=993a3823fd2cfd5a1058b749d67ac1ec81fa4ba8;hpb=edd0e97bfdc544114f30bf4c13a929631c44a555;p=alttp.git diff --git a/resources/js/components/results/Item.js b/resources/js/components/results/Item.js index 993a382..0d73105 100644 --- a/resources/js/components/results/Item.js +++ b/resources/js/components/results/Item.js @@ -2,26 +2,78 @@ import PropTypes from 'prop-types'; import React from 'react'; import { withTranslation } from 'react-i18next'; +import Icon from '../common/Icon'; import Box from '../users/Box'; import { formatTime } from '../../helpers/Result'; import { findResult } from '../../helpers/Participant'; -import i18n from '../../i18n'; +import { maySeeResults } from '../../helpers/permissions'; +import { withUser } from '../../helpers/UserContext'; + +const getIcon = (result, maySee) => { + if (!result || !result.has_finished) { + return ; + } + if (result.forfeit && maySee) { + return ; + } + if (result.placement === 1 && maySee) { + return ; + } + if (result.placement === 2 && maySee) { + return ; + } + if (result.placement === 3 && maySee) { + return ; + } + return ; +}; + +const getTime = (result, maySee) => { + if (!result || !maySee) { + return null; + } + if (result.time) { + return formatTime(result); + } + if (result.forfeit) { + return 'DNF'; + } + return '?'; +}; + +const getClassName = result => { + const classNames = ['status']; + if (result && result.has_finished) { + classNames.push('finished'); + if (result.comment) { + classNames.push('has-comment'); + } + } else { + classNames.push('pending'); + } + return classNames.join(' '); +}; const Item = ({ participant, round, + tournament, + user, }) => { const result = findResult(participant, round); - return ( -
- - {result ? -
- {i18n.t('results.time', { time: formatTime(result) })} -
- : null} + const maySee = maySeeResults(user, tournament, round); + return
+ +
+ + {getTime(result, maySee)} + + {getIcon(result, maySee)}
- ); +
; }; Item.propTypes = { @@ -33,6 +85,8 @@ Item.propTypes = { }), tournament: PropTypes.shape({ }), + user: PropTypes.shape({ + }), }; -export default withTranslation()(Item); +export default withTranslation()(withUser(Item));