import moment from 'moment'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import TextTruncate from 'react-text-truncate'; import BookCover from 'Book/BookCover'; import HeartRating from 'Components/HeartRating'; import Icon from 'Components/Icon'; import Label from 'Components/Label'; import Link from 'Components/Link/Link'; import { icons, sizes } from 'Helpers/Props'; import dimensions from 'Styles/Variables/dimensions'; import fonts from 'Styles/Variables/fonts'; import stripHtml from 'Utilities/String/stripHtml'; import translate from 'Utilities/String/translate'; import AddNewBookModal from './AddNewBookModal'; import styles from './AddNewBookSearchResult.css'; const columnPadding = parseInt(dimensions.authorIndexColumnPadding); const columnPaddingSmallScreen = parseInt(dimensions.authorIndexColumnPaddingSmallScreen); const defaultFontSize = parseInt(fonts.defaultFontSize); const lineHeight = parseFloat(fonts.lineHeight); function calculateHeight(rowHeight, isSmallScreen) { let height = rowHeight - 70; if (isSmallScreen) { height -= columnPaddingSmallScreen; } else { height -= columnPadding; } return height; } class AddNewBookSearchResult extends Component { // // Lifecycle constructor(props, context) { super(props, context); this.state = { isNewAddBookModalOpen: false }; } componentDidUpdate(prevProps) { if (!prevProps.isExistingBook && this.props.isExistingBook) { this.onAddBookModalClose(); } } // // Listeners onPress = () => { this.setState({ isNewAddBookModalOpen: true }); } onAddBookModalClose = () => { this.setState({ isNewAddBookModalOpen: false }); } onMBLinkPress = (event) => { event.stopPropagation(); } // // Render render() { const { foreignBookId, titleSlug, title, seriesTitle, releaseDate, disambiguation, overview, ratings, images, author, editions, isExistingBook, isExistingAuthor, isSmallScreen } = this.props; const { isNewAddBookModalOpen } = this.state; const linkProps = isExistingBook ? { to: `/book/${titleSlug}` } : { onPress: this.onPress }; const height = calculateHeight(230, isSmallScreen); return (