]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/results/Item.js
a2ee8e392b82a392b76236b8bab92e4e7806d6f7
[alttp.git] / resources / js / components / results / Item.js
1 import PropTypes from 'prop-types';
2 import React, { useState } from 'react';
3 import { Button } from 'react-bootstrap';
4
5 import DetailDialog from './DetailDialog';
6 import Box from '../users/Box';
7 import { getIcon, getTime } from '../../helpers/Result';
8 import { findResult } from '../../helpers/Participant';
9 import { maySeeResults } from '../../helpers/permissions';
10 import { withUser } from '../../helpers/UserContext';
11
12 const getClassName = result => {
13         const classNames = ['status'];
14         if (result && result.has_finished) {
15                 classNames.push('finished');
16                 if (result.comment) {
17                         classNames.push('has-comment');
18                 }
19         } else {
20                 classNames.push('pending');
21         }
22         return classNames.join(' ');
23 };
24
25 const Item = ({
26         participant,
27         round,
28         tournament,
29         user,
30 }) => {
31         const [showDialog, setShowDialog] = useState(false);
32         const result = findResult(participant, round);
33         const maySee = maySeeResults(user, tournament, round);
34         return <div className="result">
35                 <Box user={participant.user} />
36                 <Button
37                         className={getClassName(result)}
38                         onClick={() => setShowDialog(true)}
39                         title={maySee && result && result.comment ? result.comment : null}
40                 >
41                         <span className="time">
42                                 {getTime(result, maySee)}
43                         </span>
44                         {getIcon(result, maySee)}
45                 </Button>
46                 <DetailDialog
47                         onHide={() => setShowDialog(false)}
48                         participant={participant}
49                         round={round}
50                         show={showDialog}
51                         tournament={tournament}
52                 />
53         </div>;
54 };
55
56 Item.propTypes = {
57         participant: PropTypes.shape({
58                 user: PropTypes.shape({
59                 }),
60         }),
61         round: PropTypes.shape({
62         }),
63         tournament: PropTypes.shape({
64         }),
65         user: PropTypes.shape({
66         }),
67 };
68
69 export default withUser(Item);