import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { Link } from 'react-router'
import { bindActionCreators } from 'redux'
import Thumbnail from './Thumbnail'
import Icon from './Icon'
import URILink from './URILink'
import SpotifyAuthenticationFrame from '../components/Fields/SpotifyAuthenticationFrame'
import LastfmAuthenticationFrame from '../components/Fields/LastfmAuthenticationFrame'
import GeniusAuthenticationFrame from '../components/Fields/GeniusAuthenticationFrame'
import Snapcast from '../components/Snapcast'
import * as uiActions from '../services/ui/actions'
import * as coreActions from '../services/core/actions'
import * as mopidyActions from '../services/mopidy/actions'
import * as pusherActions from '../services/pusher/actions'
import * as spotifyActions from '../services/spotify/actions'
import * as lastfmActions from '../services/lastfm/actions'
import * as geniusActions from '../services/genius/actions'
class Services extends React.Component{
constructor(props){
super(props);
this.state = {
country: this.props.spotify.country,
locale: this.props.spotify.locale,
input_in_focus: null
}
}
componentDidMount(){
if (this.props.lastfm.session && this.props.core.users["lastfm:user:"+this.props.lastfm.session.name] === undefined){
this.props.lastfmActions.getMe();
}
}
componentWillReceiveProps(newProps){
var changed = false
var state = this.state
if (newProps.spotify.country != this.state.country && this.state.input_in_focus != 'country'){
state.country = newProps.spotify.country
changed = true
}
if (newProps.spotify.locale != this.state.locale && this.state.input_in_focus != 'locale'){
state.locale = newProps.spotify.locale
changed = true
}
if (changed){
this.setState(state)
}
}
handleBlur(name, value){
this.setState({input_in_focus: null})
var data = {}
data[name] = value
this.props.coreActions.set(data)
}
renderSpotify(){
var share_authorization_button = null;
if (this.props.spotify.authorization){
share_authorization_button = (
Share authorization
);
}
var user_object = this.props.spotify.me;
if (user_object){
var user = (
{user_object.display_name ? user_object.display_name : user_object.id}
{!this.props.spotify.authorization ? (Limited access) : null}
)
} else {
var user = (
Unknown
)
}
var not_installed = null;
if (!this.props.mopidy.uri_schemes || !this.props.mopidy.uri_schemes.includes('spotify:')){
not_installed = (
Mopidy-Spotify extension is not running - you will not be able to play any Spotify tracks
);
}
return (
{not_installed}
Authorization
{share_authorization_button}
{this.props.spotify.refreshing_token ? Refreshing... : this.props.spotifyActions.refreshingToken()}>Force token refresh }
);
}
renderLastfm(){
var user_object = (this.props.lastfm.session ? this.props.core.users["lastfm:user:"+this.props.lastfm.session.name] : null);
if (user_object){
var user = (
{user_object.realname ? user_object.realname : user_object.name}
)
} else {
var user = (
Unknown
)
}
return (
{this.props.lastfm.session ?
: null}
);
}
renderGenius(){
var user_object = (this.props.genius.session ? this.props.core.users["genius:user:"+this.props.genius.session.name] : null);
if (user_object){
var user = (
{user_object.realname ? user_object.realname : user_object.name}
)
} else {
var user = (
Unknown
)
}
return (
{this.props.genius.session ?
: null}
);
}
renderIcecast(){
return (
);
}
renderMenu(){
if (this.props.spotify.me){
var spotify_icon =
} else {
var spotify_icon =
}
if (this.props.lastfm.session && this.props.core.users["lastfm:user:"+this.props.lastfm.session.name]){
var lastfm_icon =
} else {
var lastfm_icon =
}
var genius_icon =
return (
{spotify_icon}
Spotify
{this.props.spotify.authorization ?
Authorized :
Read-only }
{lastfm_icon}
LastFM
{this.props.lastfm.session ?
Authorized :
Read-only }
{genius_icon}
Genius
{this.props.genius.session ?
Authorized :
Unauthorized }
Snapcast
{this.props.pusher.config.snapcast_enabled ?
Enabled :
Disabled }
Icecast
{this.props.core.http_streaming_enabled ?
Enabled :
Disabled }
);
}
renderService(){
var service = null;
switch (this.props.active){
case 'spotify':
service = this.renderSpotify();
break;
case 'lastfm':
service = this.renderLastfm();
break;
case 'genius':
service = this.renderGenius();
break;
case 'icecast':
service = this.renderIcecast();
break;
case 'snapcast':
service =
break;
}
if (service){
return (
{service}
);
} else {
return null;
}
}
render(){
return (
{this.renderMenu()}
{this.renderService()}
);
}
}
const mapStateToProps = (state, ownProps) => {
return state
}
const mapDispatchToProps = (dispatch) => {
return {
coreActions: bindActionCreators(coreActions, dispatch),
uiActions: bindActionCreators(uiActions, dispatch),
pusherActions: bindActionCreators(pusherActions, dispatch),
mopidyActions: bindActionCreators(mopidyActions, dispatch),
spotifyActions: bindActionCreators(spotifyActions, dispatch),
lastfmActions: bindActionCreators(lastfmActions, dispatch),
geniusActions: bindActionCreators(geniusActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Services)