1 import PropTypes from 'prop-types';
2 import React, { useState } from 'react';
3 import { Button } from 'react-bootstrap';
4 import { useTranslation } from 'react-i18next';
6 import DetailDialog from './DetailDialog';
7 import Icon from '../common/Icon';
8 import Box from '../users/Box';
9 import { getIcon, getTime } from '../../helpers/Result';
10 import { maySeeResults } from '../../helpers/permissions';
11 import { findResult } from '../../helpers/User';
12 import { useUser } from '../../hooks/user';
14 const getClassName = result => {
15 const classNames = ['status'];
16 if (result && result.has_finished) {
17 classNames.push('finished');
19 classNames.push('has-comment');
22 classNames.push('pending');
24 return classNames.join(' ');
27 const twitchReg = /^https?:\/\/(www\.)?twitch\.tv/;
28 const youtubeReg = /^https?:\/\/(www\.)?youtu(\.be|be\.)/;
30 const getVoDVariant = result => {
31 if (!result || !result.vod) return 'outline-secondary';
32 if (twitchReg.test(result.vod)) {
35 if (youtubeReg.test(result.vod)) {
36 return 'outline-youtube';
38 return 'outline-secondary';
41 const getVoDIcon = result => {
42 const variant = getVoDVariant(result);
43 if (variant === 'twitch') {
44 return <Icon.TWITCH title="" />;
46 if (variant === 'outline-youtube') {
47 return <Icon.YOUTUBE title="" />;
49 return <Icon.VIDEO title="" />;
57 const [showDialog, setShowDialog] = useState(false);
59 const { t } = useTranslation();
60 const { user: authUser } = useUser();
62 const result = React.useMemo(
63 () => findResult(user, round),
66 const maySee = React.useMemo(
67 () => maySeeResults(authUser, tournament, round),
68 [authUser, round, tournament],
71 return <div className="result">
73 <div className="d-flex align-items-center justify-content-between">
75 className={getClassName(result)}
76 onClick={() => setShowDialog(true)}
77 title={maySee && result && result.comment ? result.comment : null}
79 <span className="time">
80 {getTime(result, maySee)}
82 {getIcon(result, maySee)}
84 {maySee && result && result.vod ?
90 title={t('results.vod')}
91 variant={getVoDVariant(result)}
98 onHide={() => setShowDialog(false)}
101 tournament={tournament}
108 round: PropTypes.shape({
110 tournament: PropTypes.shape({
112 user: PropTypes.shape({