import PropTypes from 'prop-types'; import React, { Component } from 'react'; import TextTruncate from 'react-text-truncate'; import dimensions from 'Styles/Variables/dimensions'; import fonts from 'Styles/Variables/fonts'; import stripHtml from 'Utilities/String/stripHtml'; import { icons, kinds, sizes } from 'Helpers/Props'; import HeartRating from 'Components/HeartRating'; import Icon from 'Components/Icon'; import Label from 'Components/Label'; import Link from 'Components/Link/Link'; import AuthorPoster from 'Author/AuthorPoster'; import AddNewAuthorModal from './AddNewAuthorModal'; import styles from './AddNewAuthorSearchResult.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 - 45; if (isSmallScreen) { height -= columnPaddingSmallScreen; } else { height -= columnPadding; } return height; } class AddNewAuthorSearchResult extends Component { // // Lifecycle constructor(props, context) { super(props, context); this.state = { isNewAddAuthorModalOpen: false }; } componentDidUpdate(prevProps) { if (!prevProps.isExistingAuthor && this.props.isExistingAuthor) { this.onAddAuthorModalClose(); } } // // Listeners onPress = () => { this.setState({ isNewAddAuthorModalOpen: true }); } onAddAuthorModalClose = () => { this.setState({ isNewAddAuthorModalOpen: false }); } onMBLinkPress = (event) => { event.stopPropagation(); } // // Render render() { const { foreignAuthorId, titleSlug, authorName, year, disambiguation, status, overview, ratings, images, isExistingAuthor, isSmallScreen } = this.props; const { isNewAddAuthorModalOpen } = this.state; const linkProps = isExistingAuthor ? { to: `/author/${titleSlug}` } : { onPress: this.onPress }; const endedString = 'Deceased'; const height = calculateHeight(230, isSmallScreen); return (