2016-10-25 14:09:53 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
2017-08-09 08:52:49 +12:00
|
|
|
import ReactDOM from 'react-dom'
|
2016-12-21 21:49:20 +13:00
|
|
|
import { Router, Link, hashHistory } from 'react-router'
|
2016-11-12 16:36:36 +13:00
|
|
|
import FontAwesome from 'react-fontawesome'
|
2016-10-25 14:09:53 +13:00
|
|
|
|
2018-01-02 15:58:55 +13:00
|
|
|
import * as helpers from '../helpers'
|
2016-10-25 14:09:53 +13:00
|
|
|
import Thumbnail from './Thumbnail'
|
2016-10-25 21:36:33 +13:00
|
|
|
import ArtistSentence from './ArtistSentence'
|
2016-10-25 14:09:53 +13:00
|
|
|
|
|
|
|
|
export default class GridItem extends React.Component{
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
constructor(props){
|
2017-08-09 08:52:49 +12:00
|
|
|
super(props)
|
2016-10-25 14:09:53 +13:00
|
|
|
}
|
|
|
|
|
|
2018-02-21 12:58:32 +13:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-25 14:09:53 +13:00
|
|
|
handleClick(e){
|
2017-08-09 08:52:49 +12:00
|
|
|
if (this.props.onClick && e.target.tagName.toLowerCase() !== 'a'){
|
|
|
|
|
this.props.onClick(e)
|
2016-10-25 14:09:53 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-09 08:52:49 +12:00
|
|
|
handleContextMenu(e){
|
|
|
|
|
if (this.props.onContextMenu){
|
|
|
|
|
this.props.onContextMenu(e)
|
|
|
|
|
}
|
2016-10-31 16:49:42 +13:00
|
|
|
}
|
|
|
|
|
|
2017-08-17 08:29:14 +12:00
|
|
|
shouldComponentUpdate(nextProps, nextState){
|
2018-02-21 12:58:32 +13:00
|
|
|
return nextProps.item != this.props.item;
|
2017-08-17 08:29:14 +12:00
|
|
|
}
|
|
|
|
|
|
2017-01-14 01:01:48 +13:00
|
|
|
renderSecondary(item){
|
|
|
|
|
var output = ''
|
|
|
|
|
|
|
|
|
|
switch (item.type){
|
|
|
|
|
|
|
|
|
|
case 'playlist':
|
|
|
|
|
return (
|
2018-01-02 15:58:55 +13:00
|
|
|
<span>
|
2017-08-11 21:59:14 +12:00
|
|
|
{item.tracks_total ? item.tracks_total : 0} tracks
|
2018-01-02 15:58:55 +13:00
|
|
|
</span>
|
2017-01-14 01:01:48 +13:00
|
|
|
)
|
|
|
|
|
break
|
|
|
|
|
|
2017-03-24 23:05:43 +13:00
|
|
|
case 'artist':
|
|
|
|
|
return (
|
2018-01-02 15:58:55 +13:00
|
|
|
<span>
|
2018-02-21 12:58:32 +13:00
|
|
|
{item.followers ? item.followers.total.toLocaleString()+' followers' : null}
|
|
|
|
|
{item.albums_uris ? item.albums_uris.length+' albums' : null}
|
2018-01-02 15:58:55 +13:00
|
|
|
</span>
|
2017-08-09 08:52:49 +12:00
|
|
|
)
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case 'album':
|
|
|
|
|
return (
|
2018-01-02 15:58:55 +13:00
|
|
|
<span>
|
2017-08-09 08:52:49 +12:00
|
|
|
{item.artists ? <ArtistSentence artists={item.artists} /> : null}
|
2018-01-02 15:58:55 +13:00
|
|
|
</span>
|
2017-03-24 23:05:43 +13:00
|
|
|
)
|
|
|
|
|
break
|
|
|
|
|
|
2017-01-14 01:01:48 +13:00
|
|
|
default:
|
|
|
|
|
return (
|
2018-01-02 15:58:55 +13:00
|
|
|
<span>
|
2017-01-14 01:01:48 +13:00
|
|
|
{ item.artists ? <ArtistSentence artists={ item.artists } /> : null }
|
|
|
|
|
{ item.followers ? item.followers.total.toLocaleString()+' followers' : null }
|
2018-01-02 15:58:55 +13:00
|
|
|
</span>
|
2017-01-14 01:01:48 +13:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-02 15:58:55 +13:00
|
|
|
return output;
|
2017-01-14 01:01:48 +13:00
|
|
|
}
|
|
|
|
|
|
2016-10-25 14:09:53 +13:00
|
|
|
render(){
|
2017-08-09 08:52:49 +12:00
|
|
|
if (!this.props.item) return null
|
2016-11-08 13:36:13 +13:00
|
|
|
|
2016-10-25 14:09:53 +13:00
|
|
|
var item = this.props.item;
|
2017-10-10 13:05:28 +13:00
|
|
|
if (typeof(item.album) !== 'undefined'){
|
2016-10-25 14:09:53 +13:00
|
|
|
item.album.added_at = item.added_at;
|
|
|
|
|
item = item.album;
|
|
|
|
|
}
|
2017-08-10 08:02:10 +12:00
|
|
|
var images = null
|
2017-10-10 13:05:28 +13:00
|
|
|
if (this.props.item.images){
|
2017-08-09 08:52:49 +12:00
|
|
|
images = this.props.item.images
|
|
|
|
|
} else if (this.props.item.icons){
|
|
|
|
|
images = this.props.item.icons
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-25 14:09:53 +13:00
|
|
|
return (
|
2017-08-09 08:52:49 +12:00
|
|
|
<div className="grid-item" onClick={e => this.handleClick(e)} onContextMenu={e => this.handleContextMenu(e)}>
|
2017-08-10 08:02:10 +12:00
|
|
|
<Thumbnail size="medium" images={images} />
|
2018-01-02 15:58:55 +13:00
|
|
|
<div className="name">
|
|
|
|
|
{item.name ? item.name : <span className="dark-grey-text">{item.uri}</span>}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="secondary">
|
|
|
|
|
{this.props.show_source_icon ? <FontAwesome name={helpers.sourceIcon(item.uri)} className="source" /> : null}
|
|
|
|
|
{this.renderSecondary(item)}
|
|
|
|
|
</div>
|
2016-10-25 14:09:53 +13:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|