import moment from 'moment'; 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 { icons, 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 AlbumCover from 'Album/AlbumCover'; import AddNewAlbumModal from './AddNewAlbumModal'; import styles from './AddNewAlbumSearchResult.css'; const columnPadding = parseInt(dimensions.artistIndexColumnPadding); const columnPaddingSmallScreen = parseInt(dimensions.artistIndexColumnPaddingSmallScreen); 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 AddNewAlbumSearchResult extends Component { // // Lifecycle constructor(props, context) { super(props, context); this.state = { isNewAddAlbumModalOpen: false }; } componentDidUpdate(prevProps) { if (!prevProps.isExistingAlbum && this.props.isExistingAlbum) { this.onAddAlbumModalClose(); } } // // Listeners onPress = () => { this.setState({ isNewAddAlbumModalOpen: true }); } onAddAlbumModalClose = () => { this.setState({ isNewAddAlbumModalOpen: false }); } onMBLinkPress = (event) => { event.stopPropagation(); } // // Render render() { const { foreignAlbumId, title, releaseDate, disambiguation, albumType, secondaryTypes, overview, ratings, images, releases, artist, isExistingAlbum, isExistingArtist, isSmallScreen } = this.props; const { isNewAddAlbumModalOpen } = this.state; const linkProps = isExistingAlbum ? { to: `/album/${foreignAlbumId}` } : { onPress: this.onPress }; const height = calculateHeight(230, isSmallScreen); return (