1 import moment from 'moment';
2 import PropTypes from 'prop-types';
3 import React from 'react';
4 import { Button } from 'react-bootstrap';
5 import { useTranslation } from 'react-i18next';
7 import Channels from './Channels';
8 import Crew from './Crew';
9 import MultiLink from './MultiLink';
10 import Players from './Players';
11 import Icon from '../common/Icon';
12 import { canApplyForEpisode, canRestreamEpisode } from '../../helpers/permissions';
13 import { withUser } from '../../helpers/UserContext';
15 const isActive = episode => {
16 if (!episode.start) return false;
18 const start = moment(episode.start).subtract(10, 'minutes');
19 const end = moment(episode.start).add(episode.estimate, 'seconds');
20 return start.isBefore(now) && end.isAfter(now);
23 const Item = ({ episode, onAddRestream, onApply, onEditRestream, user }) => {
24 const { t } = useTranslation();
35 if (isActive(episode)) {
36 classNames.push('is-active');
39 const style = React.useMemo(() => {
40 if (episode.event && episode.event.corner) {
42 backgroundImage: `url(${episode.event.corner})`,
46 }, [episode.event && episode.event.corner]);
48 const hasChannels = episode.channels && episode.channels.length;
49 const hasPlayers = episode.players && episode.players.length;
51 return <div className={classNames.join(' ')} style={style}>
52 <div className="episode-start me-3 fs-4 text-end">
53 {t('schedule.startTime', { date: new Date(episode.start) })}
55 <div className="flex-fill">
56 <div className="d-flex align-items-start justify-content-between">
59 <div className="episode-title fs-4">
64 <div className="episode-event">
69 <div className="episode-channel-links text-end">
72 channels={episode.channels}
74 onEditRestream={onEditRestream}
77 {!hasChannels && hasPlayers ?
78 <MultiLink players={episode.players} />
80 {onAddRestream && canRestreamEpisode(user, episode) ?
83 onClick={() => onAddRestream(episode)}
84 title={t('episodes.addRestream')}
85 variant="outline-secondary"
94 <Players players={episode.players} />
96 {(episode.crew && episode.crew.length)
97 || canApplyForEpisode(user, episode, 'commentary')
98 || canApplyForEpisode(user, episode, 'tracking') ?
99 <Crew episode={episode} onApply={onApply} />
106 episode: PropTypes.shape({
107 channels: PropTypes.arrayOf(PropTypes.shape({
109 crew: PropTypes.arrayOf(PropTypes.shape({
111 event: PropTypes.shape({
112 corner: PropTypes.string,
113 title: PropTypes.string,
115 players: PropTypes.arrayOf(PropTypes.shape({
117 start: PropTypes.string,
118 title: PropTypes.string,
120 onAddRestream: PropTypes.func,
121 onApply: PropTypes.func,
122 onEditRestream: PropTypes.func,
123 user: PropTypes.shape({
127 export default withUser(Item);