]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/results/Item.js
add forfeit result
[alttp.git] / resources / js / components / results / Item.js
1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { withTranslation } from 'react-i18next';
4
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';
11
12 const getIcon = (result, index) => {
13         if (!result || !result.has_finished) {
14                 return <Icon.PENDING className="text-muted" size="lg" />;
15         }
16         if (result.forfeit) {
17                 return <Icon.FORFEIT className="text-danger" size="lg" />;
18         }
19         if (index === 0) {
20                 return <Icon.FIRST_PLACE className="text-gold" size="lg" />;
21         }
22         if (index === 1) {
23                 return <Icon.SECOND_PLACE className="text-silver" size="lg" />;
24         }
25         if (index === 2) {
26                 return <Icon.THIRD_PLACE className="text-bronze" size="lg" />;
27         }
28         return <Icon.FINISHED className="text-success" size="lg" />;
29 };
30
31 const Item = ({
32         index,
33         participant,
34         round,
35         tournament,
36         user,
37 }) => {
38         const result = findResult(participant, round);
39         return (
40                 <div className="result">
41                         <Box user={participant.user} />
42                         <div className="status">
43                                 <span className="time">
44                                         {result && maySeeResults(user, tournament, round) ?
45                                                 formatTime(result)
46                                         : null}
47                                 </span>
48                                 {getIcon(result, index)}
49                         </div>
50                 </div>
51         );
52 };
53
54 Item.propTypes = {
55         index: PropTypes.number,
56         participant: PropTypes.shape({
57                 user: PropTypes.shape({
58                 }),
59         }),
60         round: PropTypes.shape({
61         }),
62         tournament: PropTypes.shape({
63         }),
64         user: PropTypes.shape({
65         }),
66 };
67
68 export default withTranslation()(withUser(Item));