2016-10-03 21:21:14 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
2016-11-19 13:06:08 +13:00
|
|
|
import { Link } from 'react-router'
|
2016-10-06 16:38:06 +13:00
|
|
|
import FontAwesome from 'react-fontawesome'
|
2016-10-25 21:36:33 +13:00
|
|
|
import ArtistSentence from './ArtistSentence'
|
2016-10-31 16:49:42 +13:00
|
|
|
import Dater from './Dater'
|
2016-11-19 13:06:08 +13:00
|
|
|
|
|
|
|
|
import * as helpers from '../helpers'
|
2016-10-03 21:21:14 +13:00
|
|
|
|
|
|
|
|
export default class Track extends React.Component{
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-15 17:08:21 +13:00
|
|
|
handleMouseDown(e){
|
2016-11-16 14:58:08 +13:00
|
|
|
var target = $(e.target);
|
|
|
|
|
if( !target.is('a') && target.closest('a').length <= 0 ){
|
|
|
|
|
this.props.handleMouseDown(e);
|
|
|
|
|
}
|
2016-11-15 17:08:21 +13:00
|
|
|
}
|
2016-11-10 16:17:10 +13:00
|
|
|
|
2016-12-10 23:30:03 +13:00
|
|
|
handleTouchEnd(e){
|
|
|
|
|
var target = $(e.target);
|
|
|
|
|
if( !target.is('a') && target.closest('a').length <= 0 ){
|
|
|
|
|
this.props.handleTouchEnd(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-27 10:02:12 +13:00
|
|
|
handleContextMenu(e){
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
this.props.handleContextMenu(e);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-03 21:21:14 +13:00
|
|
|
render(){
|
2016-11-08 13:36:13 +13:00
|
|
|
if( !this.props.track ) return null
|
2016-10-06 16:38:06 +13:00
|
|
|
|
2016-11-08 13:36:13 +13:00
|
|
|
var track = this.props.track;
|
2016-10-21 23:27:50 +13:00
|
|
|
var className = 'list-item track';
|
2016-10-31 16:49:42 +13:00
|
|
|
if( typeof(track.selected) !== 'undefined' && track.selected ) className += ' selected';
|
|
|
|
|
if( track.playing ) className += ' playing';
|
2016-10-06 16:38:06 +13:00
|
|
|
|
2016-12-05 10:20:01 +13:00
|
|
|
var album = '-'
|
|
|
|
|
if( track.album ){
|
|
|
|
|
if( track.album.uri ){
|
|
|
|
|
album = <Link to={'/album/'+track.album.uri}>{track.album.name}</Link>
|
|
|
|
|
} else {
|
|
|
|
|
album = <span>{track.album.name}</span>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-06 16:38:06 +13:00
|
|
|
return (
|
2016-10-16 12:37:37 +13:00
|
|
|
<div
|
2016-10-21 09:56:07 +13:00
|
|
|
className={className}
|
2016-12-06 16:54:48 +13:00
|
|
|
onTouchStart={ e => this.props.handleTouchStart(e) }
|
2016-12-10 23:30:03 +13:00
|
|
|
onTouchEnd={ e => this.handleTouchEnd(e) }
|
2016-11-15 17:08:21 +13:00
|
|
|
onMouseDown={ e => this.handleMouseDown(e) }
|
2016-12-06 16:54:48 +13:00
|
|
|
onMouseUp={ e => this.props.handleMouseUp(e) }
|
|
|
|
|
onDoubleClick={ e => this.props.handleDoubleClick(e) }
|
2016-11-10 16:17:10 +13:00
|
|
|
onContextMenu={ e => this.handleContextMenu(e) }>
|
2016-10-25 14:09:53 +13:00
|
|
|
{ this.props.track.selected ? <FontAwesome name="check" className="select-state" fixedWidth /> : null }
|
2016-10-21 09:56:07 +13:00
|
|
|
<span className="col name">
|
2016-11-16 14:58:08 +13:00
|
|
|
{ track.name ? track.name : <span className="grey-text">{track.uri}</span> }
|
2016-10-17 22:00:29 +13:00
|
|
|
</span>
|
2016-10-21 09:56:07 +13:00
|
|
|
<span className="col artists">
|
2016-11-10 10:26:15 +13:00
|
|
|
{ track.artists ? <ArtistSentence artists={track.artists} /> : '-' }
|
2016-10-17 22:00:29 +13:00
|
|
|
</span>
|
2016-10-21 09:56:07 +13:00
|
|
|
<span className="col album">
|
2016-12-05 10:20:01 +13:00
|
|
|
{album}
|
2016-10-17 22:00:29 +13:00
|
|
|
</span>
|
2016-10-21 09:56:07 +13:00
|
|
|
<span className="col duration">
|
2016-10-31 16:49:42 +13:00
|
|
|
{ track.duration_ms ? <Dater type="length" data={track.duration_ms} /> : null }
|
|
|
|
|
{ track.length ? <Dater type="length" data={track.length} /> : null }
|
2016-10-17 22:00:29 +13:00
|
|
|
</span>
|
2016-11-06 18:29:49 +13:00
|
|
|
{ this.props.show_source_icon ? <FontAwesome className="source" name={helpers.sourceIcon(track.uri)} /> : null }
|
2016-10-06 16:38:06 +13:00
|
|
|
</div>
|
|
|
|
|
);
|
2016-10-03 21:21:14 +13:00
|
|
|
}
|
|
|
|
|
}
|