2017-08-05 22:25:25 +12:00
2019-09-05 15:36:11 +12:00
import React from 'react' ;
import { connect } from 'react-redux' ;
2019-01-09 16:56:35 +13:00
2019-09-05 15:36:11 +12:00
import { bindActionCreators } from 'redux' ;
2017-08-05 22:25:25 +12:00
2019-09-05 15:36:11 +12:00
import Header from '../components/Header' ;
import Thumbnail from '../components/Thumbnail' ;
import Icon from '../components/Icon' ;
2018-10-24 21:34:41 +13:00
import Link from '../components/Link' ;
2017-08-05 22:25:25 +12:00
2019-09-05 15:36:11 +12:00
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' ;
2019-09-10 06:59:44 +12:00
class Debug extends React . Component {
2019-09-05 15:36:11 +12:00
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 ) ;
}
2019-09-10 06:59:44 +12:00
render ( ) {
2019-09-05 15:36:11 +12:00
const options = (
< a className = "button button--default button--no-hover" onClick = { ( e ) => this . props . history . push ( '/settings' ) } >
2019-09-10 06:59:44 +12:00
< Icon name = "keyboard_backspace" / >
2019-09-05 15:36:11 +12:00
Back
< / a >
) ;
return (
< div className = "view debugger-view" >
< Header options = { options } uiActions = { this . props . uiActions } >
< Icon name = "settings" type = "material" / >
2018-05-15 21:30:57 +12:00
Debug
2019-09-05 15:36:11 +12:00
< / H e a d e r >
< div className = "content-wrapper" >
< h4 className = "underline" > User interface < / h 4 >
< form >
< div className = "field checkbox" >
< div className = "name" > Test mode < / d i v >
< div className = "input" >
{ this . state . toggling _test _mode ? < span className = "button button--working" > Applying ... < / s p a n > : ( t h i s . p r o p s . t e s t _ m o d e ? < s p a n c l a s s N a m e = " b u t t o n b u t t o n - - d e s t r u c t i v e " o n C l i c k = { ( e ) = > t h i s . t o g g l e T e s t M o d e ( e ) } > D i s a b l e < / s p a n > : < s p a n c l a s s N a m e = " b u t t o n b u t t o n - - p r i m a r y " o n C l i c k = { ( e ) = > t h i s . t o g g l e T e s t M o d e ( e ) } > E n a b l e < / s p a n > ) }
< / d i v >
< / d i v >
< div className = "field checkbox" >
< div className = "name" > Debug < / d i v >
< div className = "input" >
< label >
< input
type = "checkbox"
name = "debug_info"
checked = { this . props . debug _info }
2019-09-10 06:59:44 +12:00
onChange = { ( e ) => this . props . uiActions . set ( { debug _info : ! this . props . debug _info } ) }
2019-09-05 15:36:11 +12:00
/ >
< span className = "label" > Show debug overlay < / s p a n >
< / l a b e l >
< / d i v >
< / d i v >
< div className = "field checkbox" >
< div className = "name" > Logging < / d i v >
< div className = "input" >
< label >
< input
type = "checkbox"
name = "log_actions"
checked = { this . props . log _actions }
2019-09-10 06:59:44 +12:00
onChange = { ( e ) => this . props . uiActions . set ( { log _actions : ! this . props . log _actions } ) }
2019-09-05 15:36:11 +12:00
/ >
< span className = "label" > Log actions < / s p a n >
< / l a b e l >
< label >
< input
type = "checkbox"
name = "log_mopidy"
checked = { this . props . log _mopidy }
2019-09-10 06:59:44 +12:00
onChange = { ( e ) => this . props . uiActions . set ( { log _mopidy : ! this . props . log _mopidy } ) }
2019-09-05 15:36:11 +12:00
/ >
< span className = "label" > Log Mopidy < / s p a n >
< / l a b e l >
< label >
< input
type = "checkbox"
name = "log_pusher"
checked = { this . props . log _pusher }
2019-09-10 06:59:44 +12:00
onChange = { ( e ) => this . props . uiActions . set ( { log _pusher : ! this . props . log _pusher } ) }
2019-09-05 15:36:11 +12:00
/ >
< span className = "label" > Log Pusher < / s p a n >
< / l a b e l >
< / d i v >
< / d i v >
< div className = "field" >
< div className = "name" / >
< div className = "input" >
< a className = "button button--default" onClick = { ( e ) => this . props . uiActions . createNotification ( { content : 'Test notification' } ) } > Create notification < / a >
2019-09-10 06:59:44 +12:00
< a className = "button button--default" onClick = { ( e ) => this . props . uiActions . startProcess ( 'test_process' , "Test process" , { remaining : 50 , total : 100 } ) } > Create process notification < / a >
2019-09-05 15:36:11 +12:00
< a className = "button button--default" onClick = { ( e ) => this . props . pusherActions . request ( 'test' ) } > Run test process < / a >
< / d i v >
< / d i v >
< / f o r m >
< h4 className = "underline" > Spotify < / h 4 >
< label className = "field" >
< div className = "name" > Access token < / d i v >
< div className = "input" >
< input
type = "text"
onChange = { ( e ) => this . props . spotifyActions . authorizationGranted ( { access _token : e . target . value } ) }
2019-09-10 06:59:44 +12:00
value = { this . state . access _token }
2019-09-05 15:36:11 +12:00
/ >
< / d i v >
< / l a b e l >
< h4 className = "underline" > Mopidy < / h 4 >
< form onSubmit = { ( e ) => this . callMopidy ( e ) } >
< label className = "field" >
< div className = "name" > Call < / d i v >
< div className = "input" >
< input
type = "text"
onChange = { ( e ) => this . setState ( { mopidy _call : e . target . value } ) }
2019-09-10 06:59:44 +12:00
value = { this . state . mopidy _call }
2019-09-05 15:36:11 +12:00
/ >
< / d i v >
< / l a b e l >
< label className = "field" >
< div className = "name" > Data < / d i v >
< div className = "input" >
< textarea
onChange = { ( e ) => this . setState ( { mopidy _data : e . target . value } ) }
2019-09-10 06:59:44 +12:00
value = { this . state . mopidy _data }
2019-09-05 15:36:11 +12:00
/ >
< / d i v >
< / l a b e l >
< div className = "field" >
< div className = "name" / >
< div className = "input" >
< button type = "submit" className = "button button--default" > Send < / b u t t o n >
< / d i v >
< / d i v >
< / f o r m >
< h4 className = "underline" > Pusher < / h 4 >
< form onSubmit = { ( e ) => this . callPusher ( e ) } >
< label className = "field" >
< div className = "name" > Examples < / d i v >
< div className = "input" >
< select onChange = { ( e ) => this . setState ( { pusher _data : e . target . value } ) } >
< option value = '{"method":"get_config"}' > Get config < / o p t i o n >
< option value = '{"method":"get_version"}' > Get version < / o p t i o n >
< option value = '{"method":"get_connections"}' > Get connections < / o p t i o n >
< option value = '{"method":"get_radio"}' > Get radio < / o p t i o n >
< option value = '{"method":"get_queue_metadata"}' > Get queue metadata < / o p t i o n >
< option value = '{"method":"broadcast","data":{"method":"notification","params":{"notification":{"type":"info","title":"Testing","content":"This is my message"}}}}' > Broadcast to all clients < / o p t i o n >
< option value = '{"method":"send_message","data":{"method":"notification","params":{"notification":{"type":"info","title":"Testing","content":"This is my message"}}}}' > Broadcast to one client < / o p t i o n >
< option value = '{"method":"set_username","data":{"connection_id":"CONNECTION_ID_HERE","username":"NewUsername"}}' > Change username < / o p t i o n >
< option value = '{"method":"refresh_spotify_token"}' > Refresh Spotify token < / o p t i o n >
< option value = '{"method":"broadcast","data":{"method":"reload","params":{}}}' > Forced reload for all connected clients < / o p t i o n >
< option value = '{"method":"perform_upgrade"}' > Perform upgrade ( beta ) < / o p t i o n >
< / s e l e c t >
< / d i v >
< / l a b e l >
< label className = "field" >
< div className = "name" > Data < / d i v >
< div className = "input" >
< textarea
onChange = { ( e ) => this . setState ( { pusher _data : e . target . value } ) }
2019-09-10 06:59:44 +12:00
value = { this . state . pusher _data }
2019-09-05 15:36:11 +12:00
/ >
< / d i v >
< / l a b e l >
< div className = "field" >
< div className = "name" / >
< div className = "input" >
< button type = "submit" className = "button button--default" > Send < / b u t t o n >
< / d i v >
< / d i v >
< / f o r m >
< h4 className = "underline" > Response < / h 4 >
< pre >
{ this . props . debug _response ? JSON . stringify ( this . props . debug _response , null , 2 ) : null }
< / p r e >
< / d i v >
< / d i v >
) ;
}
2017-08-05 22:25:25 +12:00
}
2019-09-05 15:36:11 +12:00
const mapStateToProps = ( state , ownProps ) => ( {
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 ) => ( {
uiActions : bindActionCreators ( uiActions , dispatch ) ,
pusherActions : bindActionCreators ( pusherActions , dispatch ) ,
mopidyActions : bindActionCreators ( mopidyActions , dispatch ) ,
spotifyActions : bindActionCreators ( spotifyActions , dispatch ) ,
} ) ;
2019-09-10 06:59:44 +12:00
export default connect ( mapStateToProps , mapDispatchToProps ) ( Debug ) ;