import React, { PropTypes } from 'react' import { connect } from 'react-redux' import Link from './Link' 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.spotify.me && this.props.core.users[this.props.spotify.me.id] === undefined){ this.props.spotifyActions.getMe(); } if (this.props.lastfm.authorization && this.props.core.users["lastfm:user:"+this.props.lastfm.authorization.name] === undefined){ this.props.lastfmActions.getMe(); } if (this.props.genius.me && this.props.core.users["genius:user:"+this.props.genius.me.id] === undefined){ this.props.geniusActions.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 user_object = (this.props.spotify.me && this.props.core.users[this.props.spotify.me.uri] ? this.props.core.users[this.props.spotify.me.uri] : null); if (user_object){ var user = ( {user_object.name ? user_object.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}
Country
this.setState({country: e.target.value})} onFocus={e => this.setState({input_in_focus: 'country'})} onBlur={e => this.props.spotifyActions.set({country: e.target.value})} value={ this.state.country } />
An ISO 3166-1 alpha-2 country code (eg NZ)
Locale
this.setState({locale: e.target.value})} onFocus={e => this.setState({input_in_focus: 'locale'})} onBlur={e => this.props.spotifyActions.set({locale: e.target.value})} value={this.state.locale} />
Lowercase ISO 639 language code and an uppercase ISO 3166-1 alpha-2 country code, joined by an underscore (eg en_NZ)
Current user
{user}
Authorization
{this.props.spotify.refreshing_token ? : }
); } renderLastfm(){ var user_object = (this.props.lastfm.me ? this.props.core.users["lastfm:user:"+this.props.lastfm.me.name] : null); if (user_object){ var user = ( {user_object.name} ) } else { var user = ( Unknown ) } return (
{this.props.lastfm.authorization ?
Current user
{user}
: null}
Authorization
); } renderGenius(){ var user_object = (this.props.genius.me ? this.props.core.users[this.props.genius.me.uri] : null); if (user_object){ var user = ( {user_object.name} ) } else { var user = ( Unknown ) } return (
{this.props.genius.authorization ?
Current user
{user}
: null}
Authorization
); } renderIcecast(){ return (
Enable
Location
this.props.coreActions.set({http_streaming_url: e.target.value})} value={this.props.core.http_streaming_url} />
The full URL to your stream endpoint
); } renderMenu(){ if (this.props.spotify.me && this.props.core.users[this.props.spotify.me.uri]){ var spotify_icon = } else { var spotify_icon = } if (this.props.lastfm.me && this.props.core.users[this.props.lastfm.me.uri]){ var lastfm_icon = } else { var lastfm_icon = } if (this.props.genius.me && this.props.core.users[this.props.genius.me.uri]){ var genius_icon = } else { var genius_icon = } return (
{spotify_icon}
Spotify
{this.props.spotify.authorization ? Authorized : Read-only}
{lastfm_icon}
LastFM
{this.props.lastfm.authorization ? Authorized : Read-only}
{genius_icon}
Genius
{this.props.genius.authorization ? 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)