import classNames from 'classnames'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import AuthorBanner from 'Author/AuthorBanner'; import AuthorNameLink from 'Author/AuthorNameLink'; import DeleteAuthorModal from 'Author/Delete/DeleteAuthorModal'; import EditAuthorModalConnector from 'Author/Edit/EditAuthorModalConnector'; import BookTitleLink from 'Book/BookTitleLink'; import HeartRating from 'Components/HeartRating'; import IconButton from 'Components/Link/IconButton'; import Link from 'Components/Link/Link'; import SpinnerIconButton from 'Components/Link/SpinnerIconButton'; import ProgressBar from 'Components/ProgressBar'; import RelativeDateCellConnector from 'Components/Table/Cells/RelativeDateCellConnector'; import VirtualTableRowCell from 'Components/Table/Cells/VirtualTableRowCell'; import VirtualTableSelectCell from 'Components/Table/Cells/VirtualTableSelectCell'; import TagListConnector from 'Components/TagListConnector'; import { icons } from 'Helpers/Props'; import getProgressBarKind from 'Utilities/Author/getProgressBarKind'; import formatBytes from 'Utilities/Number/formatBytes'; import translate from 'Utilities/String/translate'; import AuthorStatusCell from './AuthorStatusCell'; import hasGrowableColumns from './hasGrowableColumns'; import styles from './AuthorIndexRow.css'; class AuthorIndexRow extends Component { // // Lifecycle constructor(props, context) { super(props, context); this.state = { hasBannerError: false, isEditAuthorModalOpen: false, isDeleteAuthorModalOpen: false }; } onEditAuthorPress = () => { this.setState({ isEditAuthorModalOpen: true }); }; onEditAuthorModalClose = () => { this.setState({ isEditAuthorModalOpen: false }); }; onDeleteAuthorPress = () => { this.setState({ isEditAuthorModalOpen: false, isDeleteAuthorModalOpen: true }); }; onDeleteAuthorModalClose = () => { this.setState({ isDeleteAuthorModalOpen: false }); }; onUseSceneNumberingChange = () => { // Mock handler to satisfy `onChange` being required for `CheckInput`. // }; onBannerLoad = () => { if (this.state.hasBannerError) { this.setState({ hasBannerError: false }); } }; onBannerLoadError = () => { if (!this.state.hasBannerError) { this.setState({ hasBannerError: true }); } }; // // Render render() { const { id, monitored, status, authorName, authorNameLastFirst, titleSlug, qualityProfile, metadataProfile, nextBook, lastBook, added, statistics, genres, ratings, path, tags, images, showBanners, showTitle, showSearchAction, columns, isRefreshingAuthor, isSearchingAuthor, isEditorActive, isSelected, onRefreshAuthorPress, onSearchPress, onSelectedChange } = this.props; const { bookCount, bookFileCount, totalBookCount, sizeOnDisk } = statistics; const { hasBannerError, isEditAuthorModalOpen, isDeleteAuthorModalOpen } = this.state; return ( <> { columns.map((column) => { const { name, isVisible } = column; if (!isVisible) { return null; } if (isEditorActive && name === 'select') { return ( ); } if (name === 'status') { return ( ); } if (name === 'sortName') { return ( { showBanners ? { hasBannerError && {showTitle === 'firstLast' ? authorName : authorNameLastFirst} } : } ); } if (name === 'qualityProfileId') { return ( {qualityProfile.name} ); } if (name === 'metadataProfileId') { return ( {metadataProfile.name} ); } if (name === 'nextBook') { if (nextBook) { return ( ); } return ( None ); } if (name === 'lastBook') { if (lastBook) { return ( ); } return ( None ); } if (name === 'added') { return ( ); } if (name === 'bookProgress') { const progress = bookCount ? bookFileCount / bookCount * 100 : 100; return ( ); } if (name === 'path') { return ( {path} ); } if (name === 'sizeOnDisk') { return ( {formatBytes(sizeOnDisk)} ); } if (name === 'genres') { const joinedGenres = genres.join(', '); return ( {joinedGenres} ); } if (name === 'ratings') { return ( ); } if (name === 'tags') { return ( ); } if (name === 'actions') { return ( { showSearchAction && } ); } return null; }) } > ); } } AuthorIndexRow.propTypes = { id: PropTypes.number.isRequired, monitored: PropTypes.bool.isRequired, status: PropTypes.string.isRequired, authorName: PropTypes.string.isRequired, authorNameLastFirst: PropTypes.string.isRequired, titleSlug: PropTypes.string.isRequired, qualityProfile: PropTypes.object.isRequired, metadataProfile: PropTypes.object.isRequired, nextBook: PropTypes.object, lastBook: PropTypes.object, added: PropTypes.string, statistics: PropTypes.object.isRequired, latestBook: PropTypes.object, path: PropTypes.string.isRequired, genres: PropTypes.arrayOf(PropTypes.string).isRequired, ratings: PropTypes.object.isRequired, tags: PropTypes.arrayOf(PropTypes.number).isRequired, images: PropTypes.arrayOf(PropTypes.object).isRequired, showBanners: PropTypes.bool.isRequired, showTitle: PropTypes.string.isRequired, showSearchAction: PropTypes.bool.isRequired, columns: PropTypes.arrayOf(PropTypes.object).isRequired, isRefreshingAuthor: PropTypes.bool.isRequired, isSearchingAuthor: PropTypes.bool.isRequired, onRefreshAuthorPress: PropTypes.func.isRequired, onSearchPress: PropTypes.func.isRequired, isEditorActive: PropTypes.bool.isRequired, isSelected: PropTypes.bool, onSelectedChange: PropTypes.func.isRequired }; AuthorIndexRow.defaultProps = { statistics: { bookCount: 0, bookFileCount: 0, totalBookCount: 0 }, genres: [], tags: [] }; export default AuthorIndexRow;