import React, { PropTypes } from 'react' import ReactDOM from 'react-dom' import { Router, Link, hashHistory } from 'react-router' import FontAwesome from 'react-fontawesome' import * as helpers from '../helpers' import Thumbnail from './Thumbnail' import ArtistSentence from './ArtistSentence' export default class GridItem extends React.Component{ constructor(props){ super(props) } componentDidMount(){ if (this.props.item && !this.props.item.images){ switch (this.props.item.type){ case 'artist': this.props.lastfmActions.getArtist(this.props.item.uri, this.props.item.name); break; } } } handleClick(e){ if (this.props.onClick && e.target.tagName.toLowerCase() !== 'a'){ this.props.onClick(e) } } handleContextMenu(e){ if (this.props.onContextMenu){ this.props.onContextMenu(e) } } shouldComponentUpdate(nextProps, nextState){ return nextProps.item != this.props.item; } renderSecondary(item){ var output = '' switch (item.type){ case 'playlist': return ( {item.tracks_total ? item.tracks_total : 0} tracks ) break case 'artist': return ( {item.followers ? item.followers.total.toLocaleString()+' followers' : null} {item.albums_uris ? item.albums_uris.length+' albums' : null} ) break case 'album': return ( {item.artists ? : null} ) break default: return ( { item.artists ? : null } { item.followers ? item.followers.total.toLocaleString()+' followers' : null } ) } return output; } render(){ if (!this.props.item) return null var item = this.props.item; if (typeof(item.album) !== 'undefined'){ item.album.added_at = item.added_at; item = item.album; } var images = null if (this.props.item.images){ images = this.props.item.images } else if (this.props.item.icons){ images = this.props.item.icons } return (
this.handleClick(e)} onContextMenu={e => this.handleContextMenu(e)}>
{item.name ? item.name : {item.uri}}
{this.props.show_source_icon ? : null} {this.renderSecondary(item)}
); } }