import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { Link, hashHistory } from 'react-router' import { bindActionCreators } from 'redux' import Header from '../components/Header' import Thumbnail from '../components/Thumbnail' import Icon from '../components/Icon' import * as uiActions from '../services/ui/actions' import * as pusherActions from '../services/pusher/actions' import * as mopidyActions from '../services/mopidy/actions' import * as spotifyActions from '../services/spotify/actions' class Debug extends React.Component{ constructor(props){ super(props); this.state = { mopidy_call: 'playlists.asList', mopidy_data: '{}', pusher_data: '{"method":"get_config"}', access_token: this.props.access_token, toggling_test_mode: false } } componentDidMount(){ this.props.uiActions.setWindowTitle("Debug"); } callMopidy(e){ e.preventDefault() this.props.mopidyActions.debug(this.state.mopidy_call, JSON.parse(this.state.mopidy_data) ) } callPusher(e){ e.preventDefault() this.props.pusherActions.debug(JSON.parse(this.state.pusher_data) ) } toggleTestMode(e){ this.setState({toggling_test_mode: true}); this.props.uiActions.set({ test_mode: !this.props.test_mode }); // Wait a second to allow state to update, and then refresh setTimeout(location.reload(), 1000); } render(){ var options = ( ) return (
Debug

User interface

Test mode
{this.state.toggling_test_mode ? Applying... : (this.props.test_mode ? this.toggleTestMode(e)}>Disable : this.toggleTestMode(e)}>Enable)}
Debug
Logging
this.props.uiActions.createNotification({content: 'Test notification'})}>Create notification this.props.uiActions.startProcess('test_process', 'Test process', {total: 100, remaining: 17})}>Start process this.props.uiActions.processFinishing('test_process')}>Stop process

Spotify

Access token
this.props.spotifyActions.authorizationGranted({access_token: e.target.value})} value={this.state.access_token} />

Mopidy

this.callMopidy(e)}>
Call
this.setState({ mopidy_call: e.target.value })} value={ this.state.mopidy_call } />
Data

Pusher

this.callPusher(e)}>
Examples
Data

Response

						{ this.props.debug_response ? JSON.stringify(this.props.debug_response, null, 2) : null }
					
); } } /** * Export our component * * We also integrate our global store, using connect() **/ const mapStateToProps = (state, ownProps) => { return { connection_id: state.pusher.connection_id, access_token: (state.spotify.access_token ? state.spotify.access_token : ''), log_actions: (state.ui.log_actions ? state.ui.log_actions : false), log_pusher: (state.ui.log_pusher ? state.ui.log_pusher : false), log_mopidy: (state.ui.log_mopidy ? state.ui.log_mopidy : false), test_mode: (state.ui.test_mode ? state.ui.test_mode : false), debug_info: (state.ui.debug_info ? state.ui.debug_info : false), debug_response: state.ui.debug_response } } const mapDispatchToProps = (dispatch) => { return { uiActions: bindActionCreators(uiActions, dispatch), pusherActions: bindActionCreators(pusherActions, dispatch), mopidyActions: bindActionCreators(mopidyActions, dispatch), spotifyActions: bindActionCreators(spotifyActions, dispatch) } } export default connect(mapStateToProps, mapDispatchToProps)(Debug)