Lidarr/frontend/src/Search/Album/AddNewAlbumSearchResult.js

244 lines
6.4 KiB
JavaScript
Raw Normal View History

2019-12-16 21:21:32 +00:00
import moment from 'moment';
2017-09-04 02:20:56 +00:00
import PropTypes from 'prop-types';
import React, { Component } from 'react';
2017-10-22 03:49:05 +00:00
import TextTruncate from 'react-text-truncate';
2020-09-07 01:33:10 +00:00
import AlbumCover from 'Album/AlbumCover';
2017-09-04 02:20:56 +00:00
import HeartRating from 'Components/HeartRating';
import Icon from 'Components/Icon';
import Label from 'Components/Label';
import Link from 'Components/Link/Link';
2020-09-07 01:33:10 +00:00
import { icons, sizes } from 'Helpers/Props';
import dimensions from 'Styles/Variables/dimensions';
import fonts from 'Styles/Variables/fonts';
2021-10-03 15:01:09 +00:00
import translate from 'Utilities/String/translate';
2019-12-16 21:21:32 +00:00
import AddNewAlbumModal from './AddNewAlbumModal';
import styles from './AddNewAlbumSearchResult.css';
2017-09-04 02:20:56 +00:00
2017-10-22 03:49:05 +00:00
const columnPadding = parseInt(dimensions.artistIndexColumnPadding);
const columnPaddingSmallScreen = parseInt(dimensions.artistIndexColumnPaddingSmallScreen);
const defaultFontSize = parseInt(fonts.defaultFontSize);
const lineHeight = parseFloat(fonts.lineHeight);
function calculateHeight(rowHeight, isSmallScreen) {
2019-12-16 21:21:32 +00:00
let height = rowHeight - 70;
2017-10-22 03:49:05 +00:00
if (isSmallScreen) {
height -= columnPaddingSmallScreen;
} else {
height -= columnPadding;
}
return height;
}
2019-12-16 21:21:32 +00:00
class AddNewAlbumSearchResult extends Component {
2017-09-04 02:20:56 +00:00
//
// Lifecycle
constructor(props, context) {
super(props, context);
this.state = {
2019-12-16 21:21:32 +00:00
isNewAddAlbumModalOpen: false
2017-09-04 02:20:56 +00:00
};
}
componentDidUpdate(prevProps) {
2019-12-16 21:21:32 +00:00
if (!prevProps.isExistingAlbum && this.props.isExistingAlbum) {
this.onAddAlbumModalClose();
2017-09-04 02:20:56 +00:00
}
}
//
// Listeners
onPress = () => {
2019-12-16 21:21:32 +00:00
this.setState({ isNewAddAlbumModalOpen: true });
2017-09-04 02:20:56 +00:00
}
2019-12-16 21:21:32 +00:00
onAddAlbumModalClose = () => {
this.setState({ isNewAddAlbumModalOpen: false });
2017-09-04 02:20:56 +00:00
}
onMBLinkPress = (event) => {
event.stopPropagation();
}
2017-09-04 02:20:56 +00:00
//
// Render
render() {
const {
2019-12-16 21:21:32 +00:00
foreignAlbumId,
title,
releaseDate,
disambiguation,
2019-12-16 21:21:32 +00:00
albumType,
secondaryTypes,
2017-09-04 02:20:56 +00:00
overview,
ratings,
images,
2019-12-16 21:21:32 +00:00
releases,
artist,
isExistingAlbum,
isExistingArtist,
2017-09-04 02:20:56 +00:00
isSmallScreen
} = this.props;
const {
2019-12-16 21:21:32 +00:00
isNewAddAlbumModalOpen
} = this.state;
2019-12-16 21:21:32 +00:00
const linkProps = isExistingAlbum ? { to: `/album/${foreignAlbumId}` } : { onPress: this.onPress };
2017-09-04 02:20:56 +00:00
2017-10-22 03:49:05 +00:00
const height = calculateHeight(230, isSmallScreen);
2017-09-04 02:20:56 +00:00
return (
<div className={styles.searchResult}>
<Link
className={styles.underlay}
{...linkProps}
/>
<div className={styles.overlay}>
{
2019-12-16 21:21:32 +00:00
!isSmallScreen &&
2020-06-27 21:51:59 +00:00
<AlbumCover
className={styles.poster}
images={images}
size={250}
/>
}
2017-09-04 02:20:56 +00:00
<div className={styles.content}>
<div className={styles.titleRow}>
<div className={styles.titleContainer}>
<div className={styles.title}>
{title}
{
!!disambiguation &&
<span className={styles.year}>({disambiguation})</span>
}
</div>
</div>
<div className={styles.icons}>
{
isExistingAlbum ?
<Icon
className={styles.alreadyExistsIcon}
name={icons.CHECK_CIRCLE}
size={36}
2021-10-03 15:01:09 +00:00
title={translate('AlreadyInYourLibrary')}
/> :
null
}
<Link
className={styles.mbLink}
to={`https://musicbrainz.org/release-group/${foreignAlbumId}`}
onPress={this.onTVDBLinkPress}
>
2019-12-16 21:21:32 +00:00
<Icon
className={styles.mbLinkIcon}
name={icons.EXTERNAL_LINK}
size={28}
/>
</Link>
</div>
</div>
2017-09-04 02:20:56 +00:00
<div>
<Label size={sizes.LARGE}>
<HeartRating
rating={ratings.value}
iconSize={13}
/>
</Label>
{
2019-12-16 21:21:32 +00:00
!!releaseDate &&
<Label size={sizes.LARGE}>
2019-12-16 21:21:32 +00:00
{moment(releaseDate).format('YYYY')}
</Label>
}
2019-12-16 21:21:32 +00:00
<Label size={sizes.LARGE}>
{releases.length} release{releases.length > 0 ? 's' : null}
</Label>
{
2019-12-16 21:21:32 +00:00
!!albumType &&
<Label size={sizes.LARGE}>
{albumType}
</Label>
}
2019-12-16 21:21:32 +00:00
{
!!secondaryTypes &&
secondaryTypes.map((item, i) => {
return (
<Label
size={sizes.LARGE}
key={i}
>
{item}
</Label>
);
})
}
</div>
2017-09-04 02:20:56 +00:00
2017-10-22 03:49:05 +00:00
<div
className={styles.overview}
style={{
maxHeight: `${height}px`
}}
>
<TextTruncate
truncateText="…"
line={Math.floor(height / (defaultFontSize * lineHeight))}
text={overview}
/>
</div>
2017-09-04 02:20:56 +00:00
</div>
</div>
2017-09-04 02:20:56 +00:00
2019-12-16 21:21:32 +00:00
<AddNewAlbumModal
isOpen={isNewAddAlbumModalOpen && !isExistingAlbum}
isExistingArtist={isExistingArtist}
foreignAlbumId={foreignAlbumId}
albumTitle={title}
disambiguation={disambiguation}
artistName={artist.artistName}
2017-09-04 02:20:56 +00:00
overview={overview}
images={images}
2019-12-16 21:21:32 +00:00
onModalClose={this.onAddAlbumModalClose}
2017-09-04 02:20:56 +00:00
/>
</div>
2017-09-04 02:20:56 +00:00
);
}
}
2019-12-16 21:21:32 +00:00
AddNewAlbumSearchResult.propTypes = {
foreignAlbumId: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
releaseDate: PropTypes.string.isRequired,
disambiguation: PropTypes.string,
2019-12-16 21:21:32 +00:00
albumType: PropTypes.string,
secondaryTypes: PropTypes.arrayOf(PropTypes.string).isRequired,
2017-09-04 02:20:56 +00:00
overview: PropTypes.string,
ratings: PropTypes.object.isRequired,
2019-12-16 21:21:32 +00:00
artist: PropTypes.object,
2017-09-04 02:20:56 +00:00
images: PropTypes.arrayOf(PropTypes.object).isRequired,
2019-12-16 21:21:32 +00:00
releases: PropTypes.arrayOf(PropTypes.object).isRequired,
isExistingAlbum: PropTypes.bool.isRequired,
isExistingArtist: PropTypes.bool.isRequired,
2017-09-04 02:20:56 +00:00
isSmallScreen: PropTypes.bool.isRequired
};
2019-12-16 21:21:32 +00:00
export default AddNewAlbumSearchResult;