import React from 'react'; import { uriType, scrollTo, sourceIcon, } from '../util/helpers'; import Link from './Link'; import Icon from './Icon'; import Thumbnail from './Thumbnail'; import LinksSentence from './LinksSentence'; import { I18n } from '../locale'; export default class GridItem extends React.Component { componentDidMount() { const { mopidyActions, spotifyActions, spotifyAvailable, item, } = this.props; if (!item || item.images) return; switch (uriType(item.uri)) { case 'artist': if (spotifyActions && spotifyAvailable) { //spotifyActions.getArtistImages(item); } break; case 'album': // If Mopidy doesn't find any images, then it will pass on the call to LastFM if (mopidyActions) { mopidyActions.getImages([item.uri]); } break; default: break; } } shouldComponentUpdate = (nextProps) => { const { item } = this.props; return nextProps.item !== item; } onContextMenu = (e) => { const { onContextMenu } = this.props; if (onContextMenu) { onContextMenu(e); } } renderSecondary = ({ uri, tracks_total, followers, albums_uris, artists, }) => { switch (uriType(uri)) { case 'playlist': return ( ); case 'artist': return ( {followers && } {albums_uris && } ); case 'album': return ( {artists && } ); default: return ( {artists && } {followers && } ); } } render = () => { const { item: { album }, link: customLink, type, show_source_icon, } = this.props; let { item } = this.props; if (!item) return null; if (album) item = { ...item, ...album }; const link = customLink || `/${type}/${encodeURIComponent(item.uri)}`; return (
{item.name ? item.name : {item.uri}}
{show_source_icon && ( )} {this.renderSecondary(item)}
); } }