]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/results/Item.js
random comments on profile page
[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 { maySeeResults } from '../../helpers/permissions';
9 import { findResult } from '../../helpers/User';
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         authUser,
27         round,
28         tournament,
29         user,
30 }) => {
31         const [showDialog, setShowDialog] = useState(false);
32         const result = findResult(user, round);
33         const maySee = maySeeResults(authUser, tournament, round);
34         return <div className="result">
35                 <Box user={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                         round={round}
49                         show={showDialog}
50                         tournament={tournament}
51                         user={user}
52                 />
53         </div>;
54 };
55
56 Item.propTypes = {
57         authUser: PropTypes.shape({
58         }),
59         round: PropTypes.shape({
60         }),
61         tournament: PropTypes.shape({
62         }),
63         user: PropTypes.shape({
64         }),
65 };
66
67 export default withUser(Item, 'authUser');