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

115 lines
2.7 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 * 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){
super(props)
2016-10-25 14:09:53 +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){
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 (
<span>
2017-08-11 21:59:14 +12:00
{item.tracks_total ? item.tracks_total : 0} tracks
</span>
)
break
2017-03-24 23:05:43 +13:00
case 'artist':
return (
<span>
{item.followers ? item.followers.total.toLocaleString()+' followers' : null}
{item.albums_uris ? item.albums_uris.length+' albums' : null}
</span>
)
break
case 'album':
return (
<span>
{item.artists ? <ArtistSentence artists={item.artists} /> : null}
</span>
2017-03-24 23:05:43 +13:00
)
break
default:
return (
<span>
{ item.artists ? <ArtistSentence artists={ item.artists } /> : null }
{ item.followers ? item.followers.total.toLocaleString()+' followers' : null }
</span>
)
}
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;
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){
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>
<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>
);
}
}