You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
225 lines
5.7 KiB
225 lines
5.7 KiB
7 years ago
|
import PropTypes from 'prop-types';
|
||
|
import React, { Component } from 'react';
|
||
7 years ago
|
import TextTruncate from 'react-text-truncate';
|
||
|
import dimensions from 'Styles/Variables/dimensions';
|
||
|
import fonts from 'Styles/Variables/fonts';
|
||
7 years ago
|
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 ArtistPoster from 'Artist/ArtistPoster';
|
||
7 years ago
|
import AddNewArtistModal from './AddNewArtistModal';
|
||
|
import styles from './AddNewArtistSearchResult.css';
|
||
7 years ago
|
|
||
7 years ago
|
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 - 45;
|
||
|
|
||
|
if (isSmallScreen) {
|
||
|
height -= columnPaddingSmallScreen;
|
||
|
} else {
|
||
|
height -= columnPadding;
|
||
|
}
|
||
|
|
||
|
return height;
|
||
|
}
|
||
|
|
||
7 years ago
|
class AddNewArtistSearchResult extends Component {
|
||
7 years ago
|
|
||
|
//
|
||
|
// Lifecycle
|
||
|
|
||
|
constructor(props, context) {
|
||
|
super(props, context);
|
||
|
|
||
|
this.state = {
|
||
7 years ago
|
isNewAddArtistModalOpen: false
|
||
7 years ago
|
};
|
||
|
}
|
||
|
|
||
|
componentDidUpdate(prevProps) {
|
||
7 years ago
|
if (!prevProps.isExistingArtist && this.props.isExistingArtist) {
|
||
7 years ago
|
this.onAddArtistModalClose();
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
|
//
|
||
|
// Listeners
|
||
|
|
||
|
onPress = () => {
|
||
7 years ago
|
this.setState({ isNewAddArtistModalOpen: true });
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
onAddArtistModalClose = () => {
|
||
7 years ago
|
this.setState({ isNewAddArtistModalOpen: false });
|
||
7 years ago
|
}
|
||
|
|
||
5 years ago
|
onMBLinkPress = (event) => {
|
||
|
event.stopPropagation();
|
||
|
}
|
||
|
|
||
7 years ago
|
//
|
||
|
// Render
|
||
|
|
||
|
render() {
|
||
|
const {
|
||
|
foreignArtistId,
|
||
|
artistName,
|
||
|
year,
|
||
7 years ago
|
disambiguation,
|
||
|
artistType,
|
||
7 years ago
|
status,
|
||
|
overview,
|
||
|
ratings,
|
||
|
images,
|
||
7 years ago
|
isExistingArtist,
|
||
7 years ago
|
isSmallScreen
|
||
|
} = this.props;
|
||
|
|
||
6 years ago
|
const {
|
||
|
isNewAddArtistModalOpen
|
||
|
} = this.state;
|
||
|
|
||
6 years ago
|
const linkProps = isExistingArtist ? { to: `/artist/${foreignArtistId}` } : { onPress: this.onPress };
|
||
5 years ago
|
|
||
5 years ago
|
const endedString = artistType === 'Person' ? 'Deceased' : 'Ended';
|
||
7 years ago
|
|
||
7 years ago
|
const height = calculateHeight(230, isSmallScreen);
|
||
|
|
||
7 years ago
|
return (
|
||
6 years ago
|
<div>
|
||
|
<Link
|
||
|
className={styles.searchResult}
|
||
|
{...linkProps}
|
||
|
>
|
||
|
{
|
||
5 years ago
|
isSmallScreen ?
|
||
|
null :
|
||
|
<ArtistPoster
|
||
|
className={styles.poster}
|
||
|
images={images}
|
||
|
size={250}
|
||
|
overflow={true}
|
||
|
/>
|
||
6 years ago
|
}
|
||
7 years ago
|
|
||
5 years ago
|
<div className={styles.content}>
|
||
6 years ago
|
<div className={styles.name}>
|
||
|
{artistName}
|
||
7 years ago
|
|
||
6 years ago
|
{
|
||
5 years ago
|
!name.contains(year) && year ?
|
||
|
<span className={styles.year}>
|
||
|
({year})
|
||
|
</span> :
|
||
|
null
|
||
6 years ago
|
}
|
||
7 years ago
|
|
||
6 years ago
|
{
|
||
|
!!disambiguation &&
|
||
7 years ago
|
<span className={styles.year}>({disambiguation})</span>
|
||
6 years ago
|
}
|
||
|
|
||
|
{
|
||
5 years ago
|
isExistingArtist ?
|
||
|
<Icon
|
||
|
className={styles.alreadyExistsIcon}
|
||
|
name={icons.CHECK_CIRCLE}
|
||
|
size={36}
|
||
|
title="Already in your library"
|
||
|
/> :
|
||
|
null
|
||
6 years ago
|
}
|
||
5 years ago
|
|
||
|
<Link
|
||
|
className={styles.mbLink}
|
||
|
to={`https://musicbrainz.org/artist/${foreignArtistId}`}
|
||
|
onPress={this.onMBLinkPress}
|
||
|
>
|
||
|
<Icon
|
||
|
className={styles.mbLinkIcon}
|
||
|
name={icons.EXTERNAL_LINK}
|
||
|
size={28}
|
||
|
/>
|
||
|
</Link>
|
||
6 years ago
|
</div>
|
||
7 years ago
|
|
||
6 years ago
|
<div>
|
||
|
<Label size={sizes.LARGE}>
|
||
|
<HeartRating
|
||
|
rating={ratings.value}
|
||
|
iconSize={13}
|
||
|
/>
|
||
|
</Label>
|
||
|
|
||
|
{
|
||
5 years ago
|
artistType ?
|
||
6 years ago
|
<Label size={sizes.LARGE}>
|
||
|
{artistType}
|
||
5 years ago
|
</Label> :
|
||
|
null
|
||
6 years ago
|
}
|
||
|
|
||
|
{
|
||
5 years ago
|
status === 'ended' ?
|
||
6 years ago
|
<Label
|
||
|
kind={kinds.DANGER}
|
||
|
size={sizes.LARGE}
|
||
|
>
|
||
5 years ago
|
{endedString}
|
||
5 years ago
|
</Label> :
|
||
|
null
|
||
6 years ago
|
}
|
||
|
</div>
|
||
7 years ago
|
|
||
7 years ago
|
<div
|
||
|
className={styles.overview}
|
||
|
style={{
|
||
|
maxHeight: `${height}px`
|
||
|
}}
|
||
|
>
|
||
|
<TextTruncate
|
||
|
truncateText="…"
|
||
|
line={Math.floor(height / (defaultFontSize * lineHeight))}
|
||
|
text={overview}
|
||
|
/>
|
||
|
</div>
|
||
7 years ago
|
</div>
|
||
6 years ago
|
</Link>
|
||
7 years ago
|
|
||
7 years ago
|
<AddNewArtistModal
|
||
6 years ago
|
isOpen={isNewAddArtistModalOpen && !isExistingArtist}
|
||
7 years ago
|
foreignArtistId={foreignArtistId}
|
||
|
artistName={artistName}
|
||
5 years ago
|
disambiguation={disambiguation}
|
||
7 years ago
|
year={year}
|
||
|
overview={overview}
|
||
|
images={images}
|
||
7 years ago
|
onModalClose={this.onAddArtistModalClose}
|
||
7 years ago
|
/>
|
||
6 years ago
|
</div>
|
||
7 years ago
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
AddNewArtistSearchResult.propTypes = {
|
||
7 years ago
|
foreignArtistId: PropTypes.string.isRequired,
|
||
|
artistName: PropTypes.string.isRequired,
|
||
|
year: PropTypes.number,
|
||
7 years ago
|
disambiguation: PropTypes.string,
|
||
|
artistType: PropTypes.string,
|
||
7 years ago
|
status: PropTypes.string.isRequired,
|
||
|
overview: PropTypes.string,
|
||
|
ratings: PropTypes.object.isRequired,
|
||
|
images: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||
7 years ago
|
isExistingArtist: PropTypes.bool.isRequired,
|
||
7 years ago
|
isSmallScreen: PropTypes.bool.isRequired
|
||
|
};
|
||
|
|
||
7 years ago
|
export default AddNewArtistSearchResult;
|