import PropTypes from 'prop-types'; import React, { Component } from 'react'; import ProtocolLabel from 'Activity/Queue/ProtocolLabel'; import BookFormats from 'Book/BookFormats'; import BookQuality from 'Book/BookQuality'; import Icon from 'Components/Icon'; import Link from 'Components/Link/Link'; import SpinnerIconButton from 'Components/Link/SpinnerIconButton'; import ConfirmModal from 'Components/Modal/ConfirmModal'; import TableRowCell from 'Components/Table/Cells/TableRowCell'; import TableRow from 'Components/Table/TableRow'; import Popover from 'Components/Tooltip/Popover'; import Tooltip from 'Components/Tooltip/Tooltip'; import { icons, kinds, tooltipPositions } from 'Helpers/Props'; import formatDateTime from 'Utilities/Date/formatDateTime'; import formatAge from 'Utilities/Number/formatAge'; import formatBytes from 'Utilities/Number/formatBytes'; import formatCustomFormatScore from 'Utilities/Number/formatCustomFormatScore'; import translate from 'Utilities/String/translate'; import Peers from './Peers'; import styles from './InteractiveSearchRow.css'; function getDownloadIcon(isGrabbing, isGrabbed, grabError) { if (isGrabbing) { return icons.SPINNER; } else if (isGrabbed) { return icons.DOWNLOADING; } else if (grabError) { return icons.DOWNLOADING; } return icons.DOWNLOAD; } function getDownloadKind(isGrabbed, grabError, downloadAllowed) { if (isGrabbed) { return kinds.SUCCESS; } if (grabError || !downloadAllowed) { return kinds.DANGER; } return kinds.DEFAULT; } function getDownloadTooltip(isGrabbing, isGrabbed, grabError) { if (isGrabbing) { return ''; } else if (isGrabbed) { return 'Added to downloaded queue'; } else if (grabError) { return grabError; } return 'Add to downloaded queue'; } class InteractiveSearchRow extends Component { // // Lifecycle constructor(props, context) { super(props, context); this.state = { isConfirmGrabModalOpen: false }; } // // Listeners onGrabPress = () => { const { guid, indexerId, onGrabPress } = this.props; onGrabPress({ guid, indexerId }); }; onConfirmGrabPress = () => { this.setState({ isConfirmGrabModalOpen: true }); }; onGrabConfirm = () => { this.setState({ isConfirmGrabModalOpen: false }); const { guid, indexerId, searchPayload, onGrabPress } = this.props; onGrabPress({ guid, indexerId, ...searchPayload }); }; onGrabCancel = () => { this.setState({ isConfirmGrabModalOpen: false }); }; // // Render render() { const { protocol, age, ageHours, ageMinutes, publishDate, title, infoUrl, indexer, size, seeders, leechers, quality, customFormatScore, customFormats, rejections, downloadAllowed, isGrabbing, isGrabbed, longDateFormat, timeFormat, grabError } = this.props; return ( {formatAge(age, ageHours, ageMinutes)} {title} {indexer} {formatBytes(size)} { protocol === 'torrent' && } } position={tooltipPositions.BOTTOM} /> { !!rejections.length && } title={translate('ReleaseRejected')} body={
    { rejections.map((rejection, index) => { return (
  • {rejection}
  • ); }) }
} position={tooltipPositions.LEFT} /> }
{ }
); } } InteractiveSearchRow.propTypes = { guid: PropTypes.string.isRequired, protocol: PropTypes.string.isRequired, age: PropTypes.number.isRequired, ageHours: PropTypes.number.isRequired, ageMinutes: PropTypes.number.isRequired, publishDate: PropTypes.string.isRequired, title: PropTypes.string.isRequired, infoUrl: PropTypes.string.isRequired, indexer: PropTypes.string.isRequired, indexerId: PropTypes.number.isRequired, size: PropTypes.number.isRequired, seeders: PropTypes.number, leechers: PropTypes.number, quality: PropTypes.object.isRequired, customFormats: PropTypes.arrayOf(PropTypes.object), customFormatScore: PropTypes.number.isRequired, rejections: PropTypes.arrayOf(PropTypes.string).isRequired, downloadAllowed: PropTypes.bool.isRequired, isGrabbing: PropTypes.bool.isRequired, isGrabbed: PropTypes.bool.isRequired, grabError: PropTypes.string, longDateFormat: PropTypes.string.isRequired, timeFormat: PropTypes.string.isRequired, searchPayload: PropTypes.object.isRequired, onGrabPress: PropTypes.func.isRequired }; InteractiveSearchRow.defaultProps = { rejections: [], isGrabbing: false, isGrabbed: false }; export default InteractiveSearchRow;