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 (
{ !isSmallScreen && }
{title} { !!disambiguation && ({disambiguation}) } { isExistingAlbum ? : null }
By: {artist.artistName} { isExistingArtist ? : null }
{ !!releaseDate && } { !!albumType && } { !!secondaryTypes && secondaryTypes.map((item, i) => { return ( ); }) }
); } } AddNewAlbumSearchResult.propTypes = { foreignAlbumId: PropTypes.string.isRequired, title: PropTypes.string.isRequired, releaseDate: PropTypes.string.isRequired, disambiguation: PropTypes.string, albumType: PropTypes.string, secondaryTypes: PropTypes.arrayOf(PropTypes.string).isRequired, overview: PropTypes.string, ratings: PropTypes.object.isRequired, artist: PropTypes.object, images: PropTypes.arrayOf(PropTypes.object).isRequired, releases: PropTypes.arrayOf(PropTypes.object).isRequired, isExistingAlbum: PropTypes.bool.isRequired, isExistingArtist: PropTypes.bool.isRequired, isSmallScreen: PropTypes.bool.isRequired }; export default AddNewAlbumSearchResult;