Files
Iris/src/js/components/GridItem.js

98 lines
2.2 KiB
JavaScript
Raw Normal View History

2016-10-25 14:09:53 +13:00
import React, { PropTypes } from 'react'
import ReactDOM from 'react-dom'
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) {
super(props)
2016-10-25 14:09:53 +13:00
}
handleClick(e){
if (this.props.onClick && e.target.tagName.toLowerCase() !== 'a'){
this.props.onClick(e)
2016-10-25 14:09:53 +13:00
}
}
handleContextMenu(e){
if (this.props.onContextMenu){
this.props.onContextMenu(e)
}
2016-10-31 16:49:42 +13:00
}
shouldComponentUpdate(nextProps, nextState){
return nextProps.item != this.props.item
}
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>
)
break
2017-03-24 23:05:43 +13:00
case 'artist':
return (
2017-08-10 08:02:10 +12:00
<div className="secondary">
{item.followers ? item.followers.total.toLocaleString()+' followers' : item.albums_uris.length+' albums'}
2017-08-10 08:02:10 +12:00
</div>
)
break
case 'album':
return (
2017-08-10 08:02:10 +12:00
<div className="secondary">
{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
default:
return (
2017-08-10 08:02:10 +12:00
<div className="secondary">
{ item.artists ? <ArtistSentence artists={ item.artists } /> : null }
{ item.followers ? item.followers.total.toLocaleString()+' followers' : null }
2017-08-10 08:02:10 +12:00
</div>
)
}
return output
}
2016-10-25 14:09:53 +13:00
render(){
if (!this.props.item) return null
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
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 (
<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>
);
}
}