import PropTypes from 'prop-types'; import React, { Component } from 'react'; import Icon from 'Components/Icon'; import IconButton from 'Components/Link/IconButton'; import Link from 'Components/Link/Link'; import SpinnerIconButton from 'Components/Link/SpinnerIconButton'; import VirtualTableRowCell from 'Components/Table/Cells/VirtualTableRowCell'; import VirtualTableSelectCell from 'Components/Table/Cells/VirtualTableSelectCell'; import Popover from 'Components/Tooltip/Popover'; import { icons, kinds, tooltipPositions } from 'Helpers/Props'; import ProtocolLabel from 'Indexer/Index/Table/ProtocolLabel'; import formatDateTime from 'Utilities/Date/formatDateTime'; import formatAge from 'Utilities/Number/formatAge'; import formatBytes from 'Utilities/Number/formatBytes'; import titleCase from 'Utilities/String/titleCase'; import translate from 'Utilities/String/translate'; import CategoryLabel from './CategoryLabel'; import Peers from './Peers'; import ReleaseLinks from './ReleaseLinks'; import styles from './SearchIndexRow.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) { if (isGrabbed) { return kinds.SUCCESS; } if (grabError) { return kinds.DANGER; } return kinds.DEFAULT; } function getDownloadTooltip(isGrabbing, isGrabbed, grabError) { if (isGrabbing) { return ''; } else if (isGrabbed) { return translate('AddedToDownloadClient'); } else if (grabError) { return grabError; } return translate('AddToDownloadClient'); } class SearchIndexRow extends Component { // // Lifecycle constructor(props, context) { super(props, context); this.state = { isConfirmGrabModalOpen: false }; } // // Listeners onGrabPress = () => { const { guid, indexerId, onGrabPress } = this.props; onGrabPress({ guid, indexerId }); }; onSavePress = () => { const { downloadUrl, fileName, onSavePress } = this.props; onSavePress({ downloadUrl, fileName }); }; // // Render render() { const { guid, protocol, downloadUrl, magnetUrl, categories, age, ageHours, ageMinutes, publishDate, title, infoUrl, indexer, size, files, grabs, seeders, leechers, imdbId, tmdbId, tvdbId, tvMazeId, indexerFlags, columns, isGrabbing, isGrabbed, grabError, longDateFormat, timeFormat, isSelected, onSelectedChange } = this.props; return ( <> { columns.map((column) => { const { isVisible } = column; if (!isVisible) { return null; } if (column.name === 'select') { return ( ); } if (column.name === 'protocol') { return ( ); } if (column.name === 'age') { return ( {formatAge(age, ageHours, ageMinutes)} ); } if (column.name === 'sortTitle') { return (
{title}
); } if (column.name === 'indexer') { return ( {indexer} ); } if (column.name === 'size') { return ( {formatBytes(size)} ); } if (column.name === 'files') { return ( {files} ); } if (column.name === 'grabs') { return ( {grabs} ); } if (column.name === 'peers') { return ( { protocol === 'torrent' && } ); } if (column.name === 'category') { return ( ); } if (column.name === 'indexerFlags') { return ( { !!indexerFlags.length && } title={translate('IndexerFlags')} body={
    { indexerFlags.map((flag, index) => { return (
  • {titleCase(flag)}
  • ); }) }
} position={tooltipPositions.LEFT} /> }
); } if (column.name === 'actions') { return ( { downloadUrl ? : null } { magnetUrl ? : null } { imdbId || tmdbId || tvdbId || tvMazeId ? ( } title={translate('Links')} body={ } kind={kinds.INVERSE} position={tooltipPositions.TOP} /> ) : null } ); } return null; }) } ); } } SearchIndexRow.propTypes = { guid: PropTypes.string.isRequired, categories: PropTypes.arrayOf(PropTypes.object).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, fileName: PropTypes.string.isRequired, infoUrl: PropTypes.string.isRequired, downloadUrl: PropTypes.string, magnetUrl: PropTypes.string, indexerId: PropTypes.number.isRequired, indexer: PropTypes.string.isRequired, size: PropTypes.number.isRequired, files: PropTypes.number, grabs: PropTypes.number, seeders: PropTypes.number, leechers: PropTypes.number, imdbId: PropTypes.number, tmdbId: PropTypes.number, tvdbId: PropTypes.number, tvMazeId: PropTypes.number, indexerFlags: PropTypes.arrayOf(PropTypes.string).isRequired, columns: PropTypes.arrayOf(PropTypes.object).isRequired, onGrabPress: PropTypes.func.isRequired, onSavePress: PropTypes.func.isRequired, isGrabbing: PropTypes.bool.isRequired, isGrabbed: PropTypes.bool.isRequired, grabError: PropTypes.string, longDateFormat: PropTypes.string.isRequired, timeFormat: PropTypes.string.isRequired, isSelected: PropTypes.bool, onSelectedChange: PropTypes.func.isRequired }; SearchIndexRow.defaultProps = { isGrabbing: false, isGrabbed: false }; export default SearchIndexRow;