2016-10-25 14:09:53 +13:00
|
|
|
|
2019-02-10 19:51:33 +13:00
|
|
|
import React from 'react';
|
2020-03-03 16:39:37 +13:00
|
|
|
import {
|
|
|
|
|
uriType,
|
|
|
|
|
scrollTo,
|
|
|
|
|
sourceIcon,
|
|
|
|
|
} from '../util/helpers';
|
2019-02-10 19:51:33 +13:00
|
|
|
import Link from './Link';
|
2019-01-15 16:57:50 +13:00
|
|
|
import Icon from './Icon';
|
|
|
|
|
import Thumbnail from './Thumbnail';
|
2019-10-05 09:10:34 +13:00
|
|
|
import LinksSentence from './LinksSentence';
|
2020-07-23 21:07:08 +12:00
|
|
|
import { I18n } from '../locale';
|
2016-10-25 14:09:53 +13:00
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
export default class GridItem extends React.Component {
|
|
|
|
|
componentDidMount() {
|
2019-09-15 21:11:57 +12:00
|
|
|
const {
|
2020-03-06 08:28:02 +13:00
|
|
|
mopidyActions,
|
2019-09-15 21:11:57 +12:00
|
|
|
spotifyActions,
|
|
|
|
|
spotifyAvailable,
|
|
|
|
|
item,
|
|
|
|
|
} = this.props;
|
2020-03-06 08:28:02 +13:00
|
|
|
|
|
|
|
|
if (!item || item.images) return;
|
|
|
|
|
|
|
|
|
|
switch (uriType(item.uri)) {
|
|
|
|
|
case 'artist':
|
|
|
|
|
if (spotifyActions && spotifyAvailable) {
|
2020-08-01 21:15:17 +12:00
|
|
|
//spotifyActions.getArtistImages(item);
|
2020-03-06 08:28:02 +13:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'album':
|
|
|
|
|
// If Mopidy doesn't find any images, then it will pass on the call to LastFM
|
2020-03-10 07:56:33 +13:00
|
|
|
if (mopidyActions) {
|
2020-09-05 11:49:28 +12:00
|
|
|
mopidyActions.getImages([item.uri]);
|
2020-03-10 07:56:33 +13:00
|
|
|
}
|
2020-03-06 08:28:02 +13:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 08:28:02 +13:00
|
|
|
shouldComponentUpdate = (nextProps) => {
|
|
|
|
|
const { item } = this.props;
|
|
|
|
|
return nextProps.item !== item;
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-03-06 08:28:02 +13:00
|
|
|
onContextMenu = (e) => {
|
|
|
|
|
const { onContextMenu } = this.props;
|
|
|
|
|
if (onContextMenu) {
|
|
|
|
|
onContextMenu(e);
|
|
|
|
|
}
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-03-06 11:01:33 +13:00
|
|
|
renderSecondary = ({
|
|
|
|
|
uri,
|
|
|
|
|
tracks_total,
|
|
|
|
|
followers,
|
|
|
|
|
albums_uris,
|
|
|
|
|
artists,
|
|
|
|
|
}) => {
|
|
|
|
|
switch (uriType(uri)) {
|
2019-09-05 15:36:11 +12:00
|
|
|
case 'playlist':
|
2020-09-11 13:53:54 +12:00
|
|
|
return (
|
2020-03-06 11:01:33 +13:00
|
|
|
<span className="grid__item__secondary__content">
|
2020-09-11 13:53:54 +12:00
|
|
|
<I18n path="specs.tracks" count={tracks_total || 0} />
|
2020-03-06 11:01:33 +13:00
|
|
|
</span>
|
2020-09-11 13:53:54 +12:00
|
|
|
);
|
2019-09-05 15:36:11 +12:00
|
|
|
|
|
|
|
|
case 'artist':
|
|
|
|
|
return (
|
|
|
|
|
<span className="grid__item__secondary__content">
|
2020-07-23 21:07:08 +12:00
|
|
|
{followers && <I18n path="specs.followers" count={followers.toLocaleString()} />}
|
2020-08-04 21:04:07 +12:00
|
|
|
{albums_uris && <I18n path="specs.albums" count={albums_uris.length} />}
|
2019-09-05 15:36:11 +12:00
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
case 'album':
|
|
|
|
|
return (
|
|
|
|
|
<span className="grid__item__secondary__content">
|
2020-03-06 11:01:33 +13:00
|
|
|
{artists && <LinksSentence nolinks items={artists} />}
|
2019-09-05 15:36:11 +12:00
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return (
|
|
|
|
|
<span className="grid__item__secondary__content">
|
2020-03-06 11:01:33 +13:00
|
|
|
{artists && <LinksSentence nolinks items={item.artists} /> }
|
2020-07-23 21:07:08 +12:00
|
|
|
{followers && <I18n path="specs.followers" count={followers.toLocaleString()} />}
|
2019-09-05 15:36:11 +12:00
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 08:28:02 +13:00
|
|
|
render = () => {
|
2020-03-06 11:01:33 +13:00
|
|
|
const {
|
|
|
|
|
item: { album },
|
|
|
|
|
link: customLink,
|
|
|
|
|
type,
|
|
|
|
|
show_source_icon,
|
|
|
|
|
} = this.props;
|
|
|
|
|
let { item } = this.props;
|
2020-03-06 08:28:02 +13:00
|
|
|
|
2020-03-06 11:01:33 +13:00
|
|
|
if (!item) return null;
|
|
|
|
|
if (album) item = { ...item, ...album };
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-03-06 08:28:02 +13:00
|
|
|
const link = customLink || `/${type}/${encodeURIComponent(item.uri)}`;
|
2019-09-05 15:36:11 +12:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Link
|
2020-03-06 08:28:02 +13:00
|
|
|
className={`grid__item grid__item--${type}`}
|
2019-09-05 15:36:11 +12:00
|
|
|
to={link}
|
2020-03-06 08:28:02 +13:00
|
|
|
onClick={scrollTo}
|
|
|
|
|
onContextMenu={this.onContextMenu}
|
2019-09-05 15:36:11 +12:00
|
|
|
>
|
2020-03-12 21:32:50 +13:00
|
|
|
<Thumbnail
|
|
|
|
|
glow
|
|
|
|
|
size="medium"
|
|
|
|
|
className="grid__item__thumbnail"
|
|
|
|
|
images={item.images || item.icons}
|
2020-04-16 20:43:02 +12:00
|
|
|
type={type}
|
2020-03-12 21:32:50 +13:00
|
|
|
/>
|
2019-09-05 15:36:11 +12:00
|
|
|
<div className="grid__item__name">
|
|
|
|
|
{item.name ? item.name : <span className="opaque-text">{item.uri}</span>}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="grid__item__secondary">
|
2020-03-06 08:28:02 +13:00
|
|
|
{show_source_icon && (
|
|
|
|
|
<Icon name={sourceIcon(item.uri)} type="fontawesome" className="source" />
|
|
|
|
|
)}
|
2019-09-05 15:36:11 +12:00
|
|
|
{this.renderSecondary(item)}
|
|
|
|
|
</div>
|
|
|
|
|
</Link>
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-10-25 14:09:53 +13:00
|
|
|
}
|