1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { Button } from 'react-bootstrap';
4 import { useTranslation } from 'react-i18next';
5 import { Link } from 'react-router-dom';
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 { hasPassed, hasSGRestream, isActive } from '../../helpers/Episode';
13 import { getLink } from '../../helpers/Event';
14 import { canApplyForEpisode, canRestreamEpisode } from '../../helpers/permissions';
15 import { useUser } from '../../hooks/user';
17 const Item = ({ episode, onAddRestream, onApply, onEditRestream }) => {
18 const { t } = useTranslation();
19 const { user } = useUser();
28 if (isActive(episode)) {
29 classNames.push('is-active');
32 const style = React.useMemo(() => {
33 if (episode.event && episode.event.corner) {
35 backgroundImage: `url(${episode.event.corner})`,
39 }, [episode.event && episode.event.corner]);
41 const hasChannels = episode.channels && episode.channels.length;
42 const hasPlayers = episode.players && episode.players.length;
44 return <div className={classNames.join(' ')} style={style}>
45 <div className="d-flex align-items-stretch">
46 <div className="episode-start me-3 fs-5 fs-md-4 text-end">
47 {t('schedule.startTime', { date: new Date(episode.start) })}
49 <div className="episode-titlebar">
50 {episode.title || episode.event ?
51 <div className="episode-title fs-5 fs-md-4">
52 {episode.title || episode.event.title}
56 <div className="episode-comment">
61 <div className="episode-channel-links ms-auto text-end">
64 channels={episode.channels}
66 onEditRestream={onEditRestream}
69 {!hasChannels && hasPlayers ?
70 <MultiLink players={episode.players} />
75 href={episode.raceroom}
77 title={t('episodes.raceroom')}
78 variant="outline-secondary"
80 <Icon.RACETIME title="" />
82 {t('episodes.raceroom')}
86 {onAddRestream && canRestreamEpisode(user, episode) ?
89 onClick={() => onAddRestream(episode)}
90 title={t('episodes.addRestream')}
91 variant="outline-secondary"
99 <div className="episode-body d-flex flex-column flex-fill">
101 <Players players={episode.players} />
103 {(episode.crew && episode.crew.length) || (!hasPassed(episode) && (
104 hasSGRestream(episode)
105 || canApplyForEpisode(user, episode, 'commentary')
106 || canApplyForEpisode(user, episode, 'tracking')
108 <div className="mb-3">
109 <Crew episode={episode} onApply={onApply} />
113 <div className="episode-event mt-auto">
114 {episode.event.description_id ?
115 <Link className="event-link" to={getLink(episode.event)}>
116 {episode.event.title}
128 episode: PropTypes.shape({
129 channels: PropTypes.arrayOf(PropTypes.shape({
131 comment: PropTypes.string,
132 crew: PropTypes.arrayOf(PropTypes.shape({
134 event: PropTypes.shape({
135 corner: PropTypes.string,
136 description_id: PropTypes.number,
137 name: PropTypes.string,
138 title: PropTypes.string,
140 players: PropTypes.arrayOf(PropTypes.shape({
142 raceroom: PropTypes.string,
143 start: PropTypes.string,
144 title: PropTypes.string,
146 onAddRestream: PropTypes.func,
147 onApply: PropTypes.func,
148 onEditRestream: PropTypes.func,