Lidarr/frontend/src/Calendar/Agenda/AgendaEvent.js

147 lines
3.5 KiB
JavaScript
Raw Normal View History

2020-09-07 01:33:10 +00:00
import classNames from 'classnames';
2017-09-04 02:20:56 +00:00
import moment from 'moment';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
2020-09-07 01:33:10 +00:00
import CalendarEventQueueDetails from 'Calendar/Events/CalendarEventQueueDetails';
2017-09-04 02:20:56 +00:00
import getStatusStyle from 'Calendar/getStatusStyle';
import Icon from 'Components/Icon';
import Link from 'Components/Link/Link';
2020-09-07 01:33:10 +00:00
import { icons } from 'Helpers/Props';
import formatTime from 'Utilities/Date/formatTime';
2021-10-03 15:01:09 +00:00
import translate from 'Utilities/String/translate';
2017-09-04 02:20:56 +00:00
import styles from './AgendaEvent.css';
class AgendaEvent extends Component {
//
// Lifecycle
constructor(props, context) {
super(props, context);
this.state = {
isDetailsModalOpen: false
};
}
//
// Listeners
onPress = () => {
this.setState({ isDetailsModalOpen: true });
2021-12-24 18:18:14 +00:00
};
2017-09-04 02:20:56 +00:00
onDetailsModalClose = () => {
this.setState({ isDetailsModalOpen: false });
2021-12-24 18:18:14 +00:00
};
2017-09-04 02:20:56 +00:00
//
// Render
render() {
const {
id,
artist,
2017-09-04 02:20:56 +00:00
title,
foreignAlbumId,
releaseDate,
2017-09-04 02:20:56 +00:00
monitored,
statistics,
2017-09-04 02:20:56 +00:00
grabbed,
queueItem,
showDate,
timeFormat,
longDateFormat,
colorImpairedMode
2017-09-04 02:20:56 +00:00
} = this.props;
const startTime = moment(releaseDate);
// const endTime = startTime.add(artist.runtime, 'minutes');
2017-09-04 02:20:56 +00:00
const downloading = !!(queueItem || grabbed);
const isMonitored = artist.monitored && monitored;
const statusStyle = getStatusStyle(id, downloading, startTime, isMonitored, statistics.percentOfTracks);
2017-09-04 02:20:56 +00:00
return (
<div>
<Link
className={styles.event}
component="div"
onPress={this.onPress}
>
<div className={styles.date}>
{
showDate &&
startTime.format(longDateFormat)
}
</div>
<div
className={classNames(
styles.eventWrapper,
styles[statusStyle],
colorImpairedMode && 'colorImpaired'
2017-09-04 02:20:56 +00:00
)}
/>
<div className={styles.time}>
{formatTime(releaseDate, timeFormat)}
2017-09-04 02:20:56 +00:00
</div>
<div className={styles.artistName}>
<Link to={`/artist/${artist.foreignArtistId}`}>
{artist.artistName}
</Link>
2017-09-04 02:20:56 +00:00
</div>
<div className={styles.albumSeparator}> - </div>
2017-09-04 02:20:56 +00:00
<div className={styles.albumTitle}>
<Link to={`/album/${foreignAlbumId}`}>
{title}
</Link>
2017-09-04 02:20:56 +00:00
</div>
{
!!queueItem &&
<CalendarEventQueueDetails
{...queueItem}
/>
}
{
!queueItem && grabbed &&
<Icon
name={icons.DOWNLOADING}
2021-10-03 15:01:09 +00:00
title={translate('AlbumIsDownloading')}
/>
2017-09-04 02:20:56 +00:00
}
</Link>
</div>
);
}
}
AgendaEvent.propTypes = {
id: PropTypes.number.isRequired,
artist: PropTypes.object.isRequired,
2017-09-04 02:20:56 +00:00
title: PropTypes.string.isRequired,
foreignAlbumId: PropTypes.string.isRequired,
albumType: PropTypes.string.isRequired,
releaseDate: PropTypes.string.isRequired,
2017-09-04 02:20:56 +00:00
monitored: PropTypes.bool.isRequired,
statistics: PropTypes.object.isRequired,
2017-09-04 02:20:56 +00:00
grabbed: PropTypes.bool,
queueItem: PropTypes.object,
showDate: PropTypes.bool.isRequired,
timeFormat: PropTypes.string.isRequired,
colorImpairedMode: PropTypes.bool.isRequired,
2017-09-04 02:20:56 +00:00
longDateFormat: PropTypes.string.isRequired
};
AgendaEvent.defaultProps = {
statistics: {
percentOfTracks: 0
}
};
2017-09-04 02:20:56 +00:00
export default AgendaEvent;