2017-10-09 21:08:27 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
2017-10-10 11:50:29 +13:00
|
|
|
import { Link } from 'react-router'
|
2017-10-09 21:08:27 +13:00
|
|
|
import { bindActionCreators } from 'redux'
|
|
|
|
|
|
|
|
|
|
import Header from '../components/Header'
|
|
|
|
|
import TrackList from '../components/TrackList'
|
|
|
|
|
import Thumbnail from '../components/Thumbnail'
|
|
|
|
|
import ArtistSentence from '../components/ArtistSentence'
|
|
|
|
|
import ArtistGrid from '../components/ArtistGrid'
|
2018-04-19 13:34:16 +12:00
|
|
|
import FollowButton from '../components/Fields/FollowButton'
|
|
|
|
|
import LastfmLoveButton from '../components/Fields/LastfmLoveButton'
|
2017-10-09 21:08:27 +13:00
|
|
|
import Dater from '../components/Dater'
|
|
|
|
|
import LazyLoadListener from '../components/LazyLoadListener'
|
|
|
|
|
import ContextMenuTrigger from '../components/ContextMenuTrigger'
|
2017-11-28 08:07:53 +13:00
|
|
|
import URILink from '../components/URILink'
|
2018-05-21 06:01:53 +12:00
|
|
|
import Icon from '../components/Icon'
|
2018-06-15 19:58:17 +12:00
|
|
|
import Popularity from '../components/Popularity'
|
2017-10-09 21:08:27 +13:00
|
|
|
|
|
|
|
|
import * as helpers from '../helpers'
|
2018-08-13 19:58:36 +12:00
|
|
|
import * as coreActions from '../services/core/actions'
|
2017-10-09 21:08:27 +13:00
|
|
|
import * as uiActions from '../services/ui/actions'
|
|
|
|
|
import * as mopidyActions from '../services/mopidy/actions'
|
|
|
|
|
import * as spotifyActions from '../services/spotify/actions'
|
2017-11-04 22:09:51 +13:00
|
|
|
import * as lastfmActions from '../services/lastfm/actions'
|
2017-10-09 21:08:27 +13:00
|
|
|
import * as geniusActions from '../services/genius/actions'
|
|
|
|
|
|
|
|
|
|
class Track extends React.Component{
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
constructor(props){
|
2017-10-09 21:08:27 +13:00
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount(){
|
|
|
|
|
this.loadTrack();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleContextMenu(e){
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
var data = { uris: [this.props.params.uri] }
|
2017-10-10 13:05:28 +13:00
|
|
|
this.props.uiActions.showContextMenu(e, data, 'track', 'click' )
|
2017-10-09 21:08:27 +13:00
|
|
|
}
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
componentWillReceiveProps(nextProps){
|
2017-10-09 21:08:27 +13:00
|
|
|
|
2017-11-04 22:09:51 +13:00
|
|
|
// if our URI has changed, fetch new track
|
2017-10-10 13:05:28 +13:00
|
|
|
if (nextProps.params.uri != this.props.params.uri){
|
2017-11-04 22:09:51 +13:00
|
|
|
this.loadTrack(nextProps)
|
2017-10-09 21:08:27 +13:00
|
|
|
|
2017-11-04 22:09:51 +13:00
|
|
|
// if mopidy has just connected AND we're not a Spotify track, go get
|
2017-10-09 21:08:27 +13:00
|
|
|
} else if (!this.props.mopidy_connected && nextProps.mopidy_connected){
|
2017-11-04 22:09:51 +13:00
|
|
|
if (helpers.uriSource(this.props.params.uri) != 'spotify'){
|
2017-11-01 08:14:26 +13:00
|
|
|
this.loadTrack(nextProps);
|
2017-10-09 21:08:27 +13:00
|
|
|
}
|
2017-10-10 11:50:29 +13:00
|
|
|
}
|
|
|
|
|
|
2017-11-06 16:59:21 +13:00
|
|
|
// We have just received our full track info (with artists)
|
|
|
|
|
if (!this.props.track.artists && nextProps.track.artists){
|
|
|
|
|
|
2018-07-04 21:10:51 +12:00
|
|
|
this.props.uiActions.setWindowTitle(nextProps.track);
|
2018-06-28 08:12:03 +12:00
|
|
|
|
2017-11-06 16:59:21 +13:00
|
|
|
// Ready to load LastFM
|
|
|
|
|
if (nextProps.lastfm_authorized){
|
2017-11-13 21:19:02 +13:00
|
|
|
this.props.lastfmActions.getTrack(nextProps.track.uri);
|
2017-11-06 16:59:21 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ready to load lyrics
|
2018-08-21 21:08:11 +12:00
|
|
|
if (nextProps.genius_authorized && !nextProps.track.lyrics_results){
|
2017-11-06 16:59:21 +13:00
|
|
|
this.props.geniusActions.findTrackLyrics(nextProps.track);
|
|
|
|
|
}
|
2017-10-09 21:08:27 +13:00
|
|
|
}
|
2018-06-29 14:26:06 +12:00
|
|
|
|
|
|
|
|
if (!this.props.track && nextProps.track){
|
|
|
|
|
this.setWindowTitle(nextProps.track);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-13 19:58:36 +12:00
|
|
|
setWindowTitle(track = this.props.track){
|
2018-06-29 14:26:06 +12:00
|
|
|
if (track){
|
|
|
|
|
var artists = "";
|
|
|
|
|
for (var i = 0; i < track.artists.length; i++){
|
|
|
|
|
if (artists != ""){
|
|
|
|
|
artists += ", ";
|
|
|
|
|
}
|
|
|
|
|
artists += track.artists[i].name;
|
|
|
|
|
}
|
|
|
|
|
this.props.uiActions.setWindowTitle(track.name+" by "+artists+" (track)");
|
|
|
|
|
} else{
|
|
|
|
|
this.props.uiActions.setWindowTitle("Track");
|
|
|
|
|
}
|
2017-10-09 21:08:27 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleContextMenu(e){
|
|
|
|
|
var data = {
|
|
|
|
|
e: e,
|
|
|
|
|
context: 'track',
|
|
|
|
|
items: [this.props.track],
|
|
|
|
|
uris: [this.props.params.uri]
|
|
|
|
|
}
|
|
|
|
|
this.props.uiActions.showContextMenu(data)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-13 21:19:02 +13:00
|
|
|
/**
|
|
|
|
|
* TODO: Identify why images being loaded breaks the thumbnail. Is there a new image array format
|
2018-08-13 19:58:36 +12:00
|
|
|
* we need to accommodate?
|
2017-11-13 21:19:02 +13:00
|
|
|
**/
|
2017-10-10 13:05:28 +13:00
|
|
|
loadTrack(props = this.props){
|
2017-10-09 21:08:27 +13:00
|
|
|
switch (helpers.uriSource(props.params.uri)){
|
|
|
|
|
|
|
|
|
|
case 'spotify':
|
|
|
|
|
if (props.track){
|
2017-10-17 20:12:59 +13:00
|
|
|
console.info('Loading track from index');
|
2017-10-10 13:32:04 +13:00
|
|
|
} else {
|
2017-11-01 08:14:26 +13:00
|
|
|
this.props.spotifyActions.getTrack(props.params.uri);
|
|
|
|
|
this.props.spotifyActions.following(props.params.uri);
|
2017-10-09 21:08:27 +13:00
|
|
|
}
|
|
|
|
|
break;
|
2017-10-10 11:50:29 +13:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
if (props.mopidy_connected){
|
|
|
|
|
if (props.track){
|
2017-10-17 20:12:59 +13:00
|
|
|
console.info('Loading track from index');
|
2017-10-10 11:50:29 +13:00
|
|
|
} else {
|
2017-10-10 13:05:28 +13:00
|
|
|
this.props.mopidyActions.getTrack(props.params.uri );
|
2017-10-10 11:50:29 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2017-10-09 21:08:27 +13:00
|
|
|
}
|
2017-10-17 20:12:59 +13:00
|
|
|
|
2017-11-06 16:59:21 +13:00
|
|
|
// We have artist info already
|
|
|
|
|
if (props.track && props.track.artists){
|
|
|
|
|
|
|
|
|
|
// Get the LastFM version of this track (provided we have artist info)
|
|
|
|
|
if (props.lastfm_authorized){
|
2017-11-13 21:19:02 +13:00
|
|
|
this.props.lastfmActions.getTrack(props.track.uri);
|
2017-11-06 16:59:21 +13:00
|
|
|
}
|
2017-11-04 22:09:51 +13:00
|
|
|
|
2017-11-06 16:59:21 +13:00
|
|
|
// Ready for lyrics
|
|
|
|
|
if (props.track && !props.track.lyrics_results){
|
|
|
|
|
this.props.geniusActions.findTrackLyrics(props.track);
|
|
|
|
|
}
|
2017-10-17 20:12:59 +13:00
|
|
|
}
|
2017-10-09 21:08:27 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
play(){
|
|
|
|
|
this.props.mopidyActions.playURIs([this.props.params.uri], this.props.params.uri)
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-17 18:54:57 +13:00
|
|
|
renderLyricsSelector(){
|
2018-02-12 08:14:13 +13:00
|
|
|
if (this.props.track.lyrics_results === undefined || this.props.track.lyrics_results === null){
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
} else if (this.props.track.lyrics_results.length <= 0){
|
2017-10-17 20:24:31 +13:00
|
|
|
return (
|
|
|
|
|
<div className="field lyrics-selector">
|
|
|
|
|
<div className="input">
|
2018-02-12 08:14:13 +13:00
|
|
|
<input type="text" disabled="disabled" value="No results" />
|
2017-10-17 20:24:31 +13:00
|
|
|
<div className="description">
|
|
|
|
|
Switch to another lyrics seach result
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2017-10-17 18:54:57 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="field lyrics-selector">
|
|
|
|
|
<div className="input">
|
|
|
|
|
<select
|
|
|
|
|
onChange={e => this.props.geniusActions.getTrackLyrics(this.props.track.uri, e.target.value)}>
|
|
|
|
|
{
|
|
|
|
|
this.props.track.lyrics_results.map(result => {
|
|
|
|
|
return (
|
2018-08-13 19:58:36 +12:00
|
|
|
<option
|
|
|
|
|
key={result.path}
|
2018-07-04 21:10:51 +12:00
|
|
|
value={result.path}
|
|
|
|
|
defaultValue={result.path == this.props.track.lyrics_path}
|
2017-10-17 18:54:57 +13:00
|
|
|
>
|
|
|
|
|
{result.title}
|
|
|
|
|
</option>
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</select>
|
|
|
|
|
<div className="description">
|
|
|
|
|
Switch to another lyrics seach result
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-09 21:08:27 +13:00
|
|
|
renderLyrics(){
|
|
|
|
|
if (helpers.isLoading(this.props.load_queue,['genius_'])){
|
|
|
|
|
return (
|
2017-10-17 20:12:59 +13:00
|
|
|
<div className="lyrics">
|
|
|
|
|
<div className="body-loader loading">
|
|
|
|
|
<div className="loader"></div>
|
|
|
|
|
</div>
|
2017-10-09 21:08:27 +13:00
|
|
|
</div>
|
|
|
|
|
);
|
2017-10-17 20:24:31 +13:00
|
|
|
} else if (this.props.track.lyrics){
|
2017-10-17 18:54:57 +13:00
|
|
|
return (
|
|
|
|
|
<div className="lyrics">
|
|
|
|
|
<div className="content" dangerouslySetInnerHTML={{__html: this.props.track.lyrics}}></div>
|
|
|
|
|
<div className="origin grey-text">
|
2018-07-04 21:10:51 +12:00
|
|
|
Origin: <a href={"https://genius.com"+this.props.track.lyrics_path} target="_blank">{"https://genius.com"+this.props.track.lyrics_path}</a>
|
2017-10-17 18:54:57 +13:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
2017-10-17 20:24:31 +13:00
|
|
|
} else {
|
|
|
|
|
return null;
|
2017-10-09 21:08:27 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(){
|
|
|
|
|
if (helpers.isLoading(this.props.load_queue,['spotify_track/'+helpers.getFromUri('trackid',this.props.params.uri)])){
|
|
|
|
|
return (
|
|
|
|
|
<div className="body-loader loading">
|
|
|
|
|
<div className="loader"></div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!this.props.track){
|
|
|
|
|
return null
|
2017-10-10 11:50:29 +13:00
|
|
|
} else {
|
|
|
|
|
var track = this.props.track
|
2017-10-09 21:08:27 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="view track-view content-wrapper">
|
|
|
|
|
|
2018-08-13 19:58:36 +12:00
|
|
|
{this.props.slim_mode ? <Header
|
|
|
|
|
icon="music"
|
|
|
|
|
title="Track"
|
|
|
|
|
handleContextMenuTrigger={e => this.handleContextMenu(e)}
|
2017-10-10 11:50:29 +13:00
|
|
|
uiActions={this.props.uiActions} /> : null}
|
2017-10-09 21:08:27 +13:00
|
|
|
|
|
|
|
|
<div className="thumbnail-wrapper">
|
2018-02-12 08:14:13 +13:00
|
|
|
<URILink type="album" uri={track.album ? track.album.uri : null}>
|
2017-11-28 08:07:53 +13:00
|
|
|
<Thumbnail size="large" canZoom images={track.images} />
|
|
|
|
|
</URILink>
|
2017-10-09 21:08:27 +13:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="title">
|
|
|
|
|
|
2017-10-10 11:50:29 +13:00
|
|
|
<h1>{track.name}</h1>
|
2018-02-12 08:14:13 +13:00
|
|
|
<h2 className="grey-text">
|
|
|
|
|
{track.album && track.album.uri ? <Link to={global.baseURL+'album/'+track.album.uri}>{track.album.name}</Link> : null}
|
|
|
|
|
{track.album && !track.album.uri ? track.album.name : null}
|
|
|
|
|
{!track.album ? "Unknown album" : null}
|
|
|
|
|
by <ArtistSentence artists={track.artists} />
|
|
|
|
|
</h2>
|
2017-10-09 21:08:27 +13:00
|
|
|
|
|
|
|
|
<ul className="details">
|
2018-05-20 20:42:20 +12:00
|
|
|
{!this.props.slim_mode ? <li className="has-tooltip"><Icon type="fontawesome" name={helpers.sourceIcon(this.props.params.uri)} /><span className="tooltip">{helpers.uriSource(this.props.params.uri)} track</span></li> : null}
|
2017-10-10 11:50:29 +13:00
|
|
|
{track.date ? <li><Dater type="date" data={track.date} /></li> : null}
|
|
|
|
|
{track.explicit ? <li><span className="flag dark">EXPLICIT</span></li> : null}
|
|
|
|
|
<li>
|
|
|
|
|
{track.disc_number ? <span>Disc {track.disc_number}</span> : null}
|
2017-10-10 13:32:04 +13:00
|
|
|
{track.disc_number && track.track_number ? <span>, </span> : null}
|
|
|
|
|
{track.track_number ? <span>Track {track.track_number}</span> : null}
|
2017-10-10 11:50:29 +13:00
|
|
|
</li>
|
2017-10-19 09:58:26 +13:00
|
|
|
{track.duration ? <li><Dater type="length" data={track.duration} /></li> : null}
|
2018-06-15 19:58:17 +12:00
|
|
|
{track.popularity ? <li><Popularity popularity={track.popularity} /></li> : null}
|
2017-10-09 21:08:27 +13:00
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="actions">
|
|
|
|
|
<button className="primary" onClick={e => this.play()}>Play</button>
|
2017-11-06 16:59:21 +13:00
|
|
|
<LastfmLoveButton uri={this.props.params.uri} artist={this.props.track.artists[0].name} track={this.props.track.name} addText="Love" removeText="Unlove" is_loved={this.props.track.userloved} />
|
2017-11-04 22:09:51 +13:00
|
|
|
<ContextMenuTrigger onTrigger={e => this.handleContextMenu(e)} />
|
2017-10-09 21:08:27 +13:00
|
|
|
</div>
|
|
|
|
|
|
2018-08-21 21:08:11 +12:00
|
|
|
{!this.props.genius_authorized ? <p className="no-results">Want track lyrics? Authorize Genius under <Link to={global.baseURL+"settings/service/genius"}>Settings</Link>.</p> : null}
|
|
|
|
|
{this.props.genius_authorized ? this.renderLyricsSelector() : null}
|
|
|
|
|
{this.props.genius_authorized ? this.renderLyrics() : null}
|
2017-10-09 21:08:27 +13:00
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Export our component
|
|
|
|
|
*
|
|
|
|
|
* We also integrate our global store, using connect()
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2017-10-26 20:36:27 +13:00
|
|
|
var uri = ownProps.params.uri;
|
2017-10-09 21:08:27 +13:00
|
|
|
return {
|
|
|
|
|
slim_mode: state.ui.slim_mode,
|
|
|
|
|
load_queue: state.ui.load_queue,
|
2017-10-26 20:36:27 +13:00
|
|
|
track: (state.core.tracks && state.core.tracks[uri] !== undefined ? state.core.tracks[uri] : false),
|
2017-10-09 21:08:27 +13:00
|
|
|
tracks: state.core.tracks,
|
|
|
|
|
artists: state.core.artists,
|
|
|
|
|
albums: state.core.albums,
|
|
|
|
|
spotify_library_albums: state.spotify.library_albums,
|
|
|
|
|
local_library_albums: state.mopidy.library_albums,
|
2017-11-06 16:59:21 +13:00
|
|
|
lastfm_authorized: state.lastfm.session,
|
2017-10-09 21:08:27 +13:00
|
|
|
spotify_authorized: state.spotify.authorization,
|
2018-08-21 21:08:11 +12:00
|
|
|
genius_authorized: state.genius.authorization,
|
2017-10-09 21:08:27 +13:00
|
|
|
mopidy_connected: state.mopidy.connected
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
2018-08-13 19:58:36 +12:00
|
|
|
coreActions: bindActionCreators(coreActions, dispatch),
|
2017-10-09 21:08:27 +13:00
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
|
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
2017-11-04 22:09:51 +13:00
|
|
|
lastfmActions: bindActionCreators(lastfmActions, dispatch),
|
2017-10-09 21:08:27 +13:00
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch),
|
|
|
|
|
geniusActions: bindActionCreators(geniusActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-13 19:58:36 +12:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Track)
|