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