import PropTypes from 'prop-types'; import React, { Component } from 'react'; import TextTruncate from 'react-text-truncate'; import AuthorPoster from 'Author/AuthorPoster'; import DeleteAuthorModal from 'Author/Delete/DeleteAuthorModal'; import EditAuthorModalConnector from 'Author/Edit/EditAuthorModalConnector'; import BookIndexProgressBar from 'Book/Index/ProgressBar/BookIndexProgressBar'; import CheckInput from 'Components/Form/CheckInput'; import IconButton from 'Components/Link/IconButton'; import Link from 'Components/Link/Link'; import SpinnerIconButton from 'Components/Link/SpinnerIconButton'; import { icons } from 'Helpers/Props'; import dimensions from 'Styles/Variables/dimensions'; import fonts from 'Styles/Variables/fonts'; import createAjaxRequest from 'Utilities/createAjaxRequest'; import stripHtml from 'Utilities/String/stripHtml'; import translate from 'Utilities/String/translate'; import BookIndexOverviewInfo from './BookIndexOverviewInfo'; import styles from './BookIndexOverview.css'; const columnPadding = parseInt(dimensions.authorIndexColumnPadding); const columnPaddingSmallScreen = parseInt(dimensions.authorIndexColumnPaddingSmallScreen); const defaultFontSize = parseInt(fonts.defaultFontSize); const lineHeight = parseFloat(fonts.lineHeight); // Hardcoded height beased on line-height of 32 + bottom margin of 10. // Less side-effecty than using react-measure. const titleRowHeight = 42; function getContentHeight(rowHeight, isSmallScreen) { const padding = isSmallScreen ? columnPaddingSmallScreen : columnPadding; return rowHeight - padding; } class BookIndexOverview extends Component { // // Lifecycle constructor(props, context) { super(props, context); this.state = { isEditAuthorModalOpen: false, isDeleteAuthorModalOpen: false, overview: '' }; } componentDidMount() { const { id } = this.props; // Note that this component is lazy loaded by the virtualised view. // We want to avoid storing overviews for *all* books which is // why it's not put into the redux store const promise = createAjaxRequest({ url: `/book/${id}/overview` }).request; promise.done((data) => { this.setState({ overview: data.overview }); }); } // // Listeners onEditAuthorPress = () => { this.setState({ isEditAuthorModalOpen: true }); } onEditAuthorModalClose = () => { this.setState({ isEditAuthorModalOpen: false }); } onDeleteAuthorPress = () => { this.setState({ isEditAuthorModalOpen: false, isDeleteAuthorModalOpen: true }); } onDeleteAuthorModalClose = () => { this.setState({ isDeleteAuthorModalOpen: false }); } onChange = ({ value, shiftKey }) => { const { id, onSelectedChange } = this.props; onSelectedChange({ id, value, shiftKey }); } // // Render render() { const { id, title, monitored, titleSlug, nextAiring, statistics, images, posterWidth, posterHeight, qualityProfile, overviewOptions, showSearchAction, showRelativeDates, shortDateFormat, longDateFormat, timeFormat, rowHeight, isSmallScreen, isRefreshingBook, isSearchingBook, onRefreshBookPress, onSearchPress, isEditorActive, isSelected, ...otherProps } = this.props; const { bookCount, sizeOnDisk, bookFileCount, totalBookCount } = statistics; const { overview, isEditAuthorModalOpen, isDeleteAuthorModalOpen } = this.state; const link = `/book/${titleSlug}`; const elementStyle = { width: `${posterWidth}px`, height: `${posterHeight}px`, objectFit: 'contain' }; const contentHeight = getContentHeight(rowHeight, isSmallScreen); const overviewHeight = contentHeight - titleRowHeight; return (