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
|
|
|
|
|
|
|
|
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{
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
2017-08-09 08:52:49 +12:00
|
|
|
super(props)
|
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-01-14 01:01:48 +13:00
|
|
|
renderSecondary(item){
|
|
|
|
|
var output = ''
|
|
|
|
|
|
|
|
|
|
switch (item.type){
|
|
|
|
|
|
|
|
|
|
case 'playlist':
|
|
|
|
|
return (
|
2017-08-10 08:02:10 +12:00
|
|
|
<div className="secondary">
|
2017-08-11 21:59:14 +12:00
|
|
|
{item.tracks_total ? item.tracks_total : 0} tracks
|
2017-08-10 08:02:10 +12:00
|
|
|
</div>
|
2017-01-14 01:01:48 +13:00
|
|
|
)
|
|
|
|
|
break
|
|
|
|
|
|
2017-03-24 23:05:43 +13:00
|
|
|
case 'artist':
|
|
|
|
|
return (
|
2017-08-10 08:02:10 +12:00
|
|
|
<div className="secondary">
|
2017-08-09 08:52:49 +12:00
|
|
|
{item.followers ? item.followers.total.toLocaleString()+' followers' : item.albums_uris.length+' albums'}
|
2017-08-10 08:02:10 +12:00
|
|
|
</div>
|
2017-08-09 08:52:49 +12:00
|
|
|
)
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case 'album':
|
|
|
|
|
return (
|
2017-08-10 08:02:10 +12:00
|
|
|
<div className="secondary">
|
2017-08-09 08:52:49 +12:00
|
|
|
{item.artists ? <ArtistSentence artists={item.artists} /> : null}
|
2017-08-10 08:02:10 +12:00
|
|
|
</div>
|
2017-03-24 23:05:43 +13:00
|
|
|
)
|
|
|
|
|
break
|
|
|
|
|
|
2017-01-14 01:01:48 +13:00
|
|
|
default:
|
|
|
|
|
return (
|
2017-08-10 08:02:10 +12:00
|
|
|
<div className="secondary">
|
2017-01-14 01:01:48 +13:00
|
|
|
{ item.artists ? <ArtistSentence artists={ item.artists } /> : null }
|
|
|
|
|
{ item.followers ? item.followers.total.toLocaleString()+' followers' : null }
|
2017-08-10 08:02:10 +12:00
|
|
|
</div>
|
2017-01-14 01:01:48 +13:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return output
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
if( typeof(item.album) !== 'undefined' ){
|
|
|
|
|
item.album.added_at = item.added_at;
|
|
|
|
|
item = item.album;
|
|
|
|
|
}
|
2017-08-10 08:02:10 +12:00
|
|
|
var images = null
|
2017-08-09 08:52:49 +12:00
|
|
|
if (this.props.item.images) {
|
|
|
|
|
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} />
|
|
|
|
|
<div className="name">{item.name ? item.name : <span className="dark-grey-text">{item.uri}</span>}</div>
|
|
|
|
|
{ this.renderSecondary(item) }
|
2016-10-25 14:09:53 +13:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|