2018-09-30 20:09:12 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { Link } from 'react-router'
|
|
|
|
|
import { createStore, bindActionCreators } from 'redux'
|
|
|
|
|
|
|
|
|
|
import Modal from './Modal';
|
|
|
|
|
import Icon from '../../components/Icon';
|
|
|
|
|
|
|
|
|
|
import * as uiActions from '../../services/ui/actions';
|
|
|
|
|
import * as pusherActions from '../../services/pusher/actions';
|
|
|
|
|
import * as helpers from '../../helpers';
|
|
|
|
|
|
|
|
|
|
class ShareConfiguration extends React.Component {
|
|
|
|
|
|
|
|
|
|
constructor(props){
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
recipients: [],
|
2018-10-01 21:51:46 +13:00
|
|
|
spotify: false,
|
|
|
|
|
lastfm: false,
|
|
|
|
|
genius: false,
|
2018-10-01 16:56:00 +13:00
|
|
|
snapcast_client_commands: false,
|
2018-10-01 21:51:46 +13:00
|
|
|
ui: false
|
2018-09-30 20:09:12 +13:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount(){
|
|
|
|
|
this.props.uiActions.setWindowTitle("Share configuration");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggleRecipient(id){
|
|
|
|
|
var recipients = this.state.recipients;
|
|
|
|
|
if (recipients.includes(id)){
|
|
|
|
|
var index = recipients.indexOf(id);
|
|
|
|
|
recipients.splice(index,1);
|
|
|
|
|
} else {
|
|
|
|
|
recipients.push(id);
|
|
|
|
|
}
|
|
|
|
|
this.setState({recipients: recipients});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleSubmit(e){
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
var configuration = {};
|
2018-10-01 21:51:46 +13:00
|
|
|
if (this.state.spotify){
|
|
|
|
|
configuration.spotify = {
|
|
|
|
|
authorization: this.props.spotify_authorization,
|
|
|
|
|
me: this.props.spotify_me
|
|
|
|
|
}
|
2018-09-30 20:09:12 +13:00
|
|
|
}
|
2018-10-01 21:51:46 +13:00
|
|
|
if (this.state.genius){
|
|
|
|
|
configuration.genius = {
|
|
|
|
|
authorization: this.props.genius_authorization,
|
|
|
|
|
me: this.props.genius_me
|
|
|
|
|
}
|
2018-09-30 20:09:12 +13:00
|
|
|
}
|
2018-10-01 21:51:46 +13:00
|
|
|
if (this.state.lastfm){
|
|
|
|
|
configuration.lastfm = {
|
|
|
|
|
authorization: this.props.lastfm_authorization,
|
|
|
|
|
me: this.props.lastfm_me
|
|
|
|
|
}
|
2018-09-30 20:09:12 +13:00
|
|
|
}
|
2018-10-01 21:51:46 +13:00
|
|
|
if (this.state.ui){
|
|
|
|
|
configuration.ui = this.props.ui;
|
2018-09-30 20:09:12 +13:00
|
|
|
}
|
2018-10-01 21:51:46 +13:00
|
|
|
if (this.state.snapcast_client_commands){
|
2018-10-01 16:56:00 +13:00
|
|
|
configuration.snapcast_client_commands = this.props.snapcast_client_commands;
|
|
|
|
|
}
|
2018-09-30 20:09:12 +13:00
|
|
|
|
|
|
|
|
for (var recipient of this.state.recipients){
|
|
|
|
|
this.props.pusherActions.deliverMessage(
|
|
|
|
|
recipient,
|
|
|
|
|
'share_configuration_received',
|
|
|
|
|
configuration
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-01 21:51:46 +13:00
|
|
|
//window.history.back();
|
2018-09-30 20:09:12 +13:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(){
|
|
|
|
|
var connections = []
|
|
|
|
|
for (var connection_id in this.props.connections){
|
|
|
|
|
if (this.props.connections.hasOwnProperty(connection_id) && connection_id != this.props.connection_id){
|
|
|
|
|
connections.push(this.props.connections[connection_id])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (connections.length > 0){
|
|
|
|
|
var recipients = (
|
|
|
|
|
<div className="input">
|
|
|
|
|
{
|
|
|
|
|
connections.map((connection, index) => {
|
|
|
|
|
return (
|
|
|
|
|
<label key={connection.connection_id}>
|
|
|
|
|
<input
|
|
|
|
|
type="checkbox"
|
|
|
|
|
name={"connection_"+connection.connection_id}
|
|
|
|
|
checked={this.state.recipients.includes(connection.connection_id)}
|
|
|
|
|
onChange={e => this.toggleRecipient(connection.connection_id)}
|
|
|
|
|
/>
|
|
|
|
|
<span className="label">
|
|
|
|
|
{ connection.username }
|
|
|
|
|
|
|
|
|
|
<span className="grey-text">
|
|
|
|
|
({ connection.ip })
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
</label>
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
var recipients = (
|
|
|
|
|
<div className="input text">
|
|
|
|
|
<span className="grey-text">
|
|
|
|
|
No peer connections
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Modal className="modal--share-authorization">
|
|
|
|
|
<h1>Share configuration</h1>
|
|
|
|
|
<form onSubmit={e => this.handleSubmit(e)}>
|
|
|
|
|
<div className="field checkbox white">
|
|
|
|
|
<div className="name">Recipients</div>
|
|
|
|
|
{recipients}
|
|
|
|
|
</div>
|
|
|
|
|
|
2018-10-01 16:56:00 +13:00
|
|
|
<div className="field checkbox checkbox--block">
|
|
|
|
|
<div className="name">Configurations</div>
|
2018-09-30 20:09:12 +13:00
|
|
|
<div className="input">
|
|
|
|
|
<label>
|
|
|
|
|
<input
|
|
|
|
|
type="checkbox"
|
|
|
|
|
name="interface"
|
2018-10-01 21:51:46 +13:00
|
|
|
checked={ this.state.ui }
|
|
|
|
|
onChange={ e => this.setState({ ui: !this.state.ui })} />
|
2018-09-30 20:09:12 +13:00
|
|
|
<span className="label">
|
|
|
|
|
UI customisation (theme, sorting, filters)
|
|
|
|
|
</span>
|
|
|
|
|
</label>
|
|
|
|
|
|
2018-10-01 16:56:00 +13:00
|
|
|
{this.props.snapcast_client_commands ? <label>
|
|
|
|
|
<input
|
|
|
|
|
type="checkbox"
|
|
|
|
|
name="snapcast_client_commands"
|
|
|
|
|
checked={this.state.snapcast_client_commands}
|
|
|
|
|
onChange={ e => this.setState({ snapcast_client_commands: !this.state.snapcast_client_commands })} />
|
|
|
|
|
<span className="label">
|
|
|
|
|
Snapcast client commands
|
|
|
|
|
</span>
|
|
|
|
|
</label> : null}
|
|
|
|
|
|
|
|
|
|
{this.props.spotify_me && this.props.spotify_authorization ? <label>
|
2018-09-30 20:09:12 +13:00
|
|
|
<input
|
|
|
|
|
type="checkbox"
|
2018-10-01 21:51:46 +13:00
|
|
|
name="spotify"
|
|
|
|
|
checked={this.state.spotify}
|
|
|
|
|
onChange={ e => this.setState({ spotify: !this.state.spotify })} />
|
2018-09-30 20:09:12 +13:00
|
|
|
<span className="label">
|
2018-10-01 16:56:00 +13:00
|
|
|
Spotify authorization <span className="grey-text"> Logged in as {this.props.spotify_me.name}</span>
|
2018-09-30 20:09:12 +13:00
|
|
|
</span>
|
2018-10-01 16:56:00 +13:00
|
|
|
</label> : null}
|
2018-09-30 20:09:12 +13:00
|
|
|
|
2018-10-01 16:56:00 +13:00
|
|
|
{this.props.lastfm_me && this.props.lastfm_authorization ? <label>
|
2018-09-30 20:09:12 +13:00
|
|
|
<input
|
|
|
|
|
type="checkbox"
|
|
|
|
|
name="lastfm_authorization"
|
2018-10-01 21:51:46 +13:00
|
|
|
checked={this.state.lastfm}
|
|
|
|
|
onChange={ e => this.setState({ lastfm: !this.state.lastfm })} />
|
2018-09-30 20:09:12 +13:00
|
|
|
<span className="label">
|
2018-10-01 16:56:00 +13:00
|
|
|
LastFM authorization <span className="grey-text"> Logged in as {this.props.lastfm_me.name}</span>
|
2018-09-30 20:09:12 +13:00
|
|
|
</span>
|
2018-10-01 16:56:00 +13:00
|
|
|
</label> : null}
|
2018-09-30 20:09:12 +13:00
|
|
|
|
2018-10-01 16:56:00 +13:00
|
|
|
{this.props.genius_me && this.props.genius_authorization ? <label>
|
2018-09-30 20:09:12 +13:00
|
|
|
<input
|
|
|
|
|
type="checkbox"
|
|
|
|
|
name="genius_authorization"
|
2018-10-01 21:51:46 +13:00
|
|
|
checked={this.state.genius}
|
|
|
|
|
onChange={ e => this.setState({ genius: !this.state.genius })} />
|
2018-09-30 20:09:12 +13:00
|
|
|
<span className="label">
|
2018-10-01 16:56:00 +13:00
|
|
|
Genius authorization <span className="grey-text"> Logged in as {this.props.genius_me.name}</span>
|
2018-09-30 20:09:12 +13:00
|
|
|
</span>
|
2018-10-01 16:56:00 +13:00
|
|
|
</label> : null}
|
2018-09-30 20:09:12 +13:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="actions centered-text">
|
2018-10-01 16:56:00 +13:00
|
|
|
{this.state.recipients.length > 0 ? <button className="primary large" onClick={e => this.handleSubmit(e)}>Send</button> : <button className="primary large" disabled="disabled" onClick={e => this.handleSubmit(e)}>Send</button>}
|
2018-09-30 20:09:12 +13:00
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</Modal>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
return {
|
|
|
|
|
spotify_authorization: state.spotify.authorization,
|
|
|
|
|
spotify_me: state.spotify.me,
|
|
|
|
|
genius_authorization: state.genius.authorization,
|
|
|
|
|
genius_me: state.genius.me,
|
|
|
|
|
lastfm_authorization: state.lastfm.authorization,
|
|
|
|
|
lastfm_me: state.lastfm.me,
|
2018-10-01 16:56:00 +13:00
|
|
|
snapcast_client_commands: state.snapcast.client_commands,
|
2018-10-01 21:51:46 +13:00
|
|
|
ui: state.ui,
|
2018-09-30 20:09:12 +13:00
|
|
|
connection_id: state.pusher.connection_id,
|
|
|
|
|
connections: state.pusher.connections
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
|
|
|
|
pusherActions: bindActionCreators(pusherActions, dispatch),
|
|
|
|
|
uiActions: bindActionCreators(uiActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(ShareConfiguration)
|