import React from 'react'; import { connect } from 'react-redux'; import { createStore, bindActionCreators } from 'redux'; import Link from '../../components/Link'; 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: [], spotify: false, lastfm: false, genius: false, ui: false, }; } componentDidMount() { this.props.uiActions.setWindowTitle('Share configuration'); } toggleRecipient(id) { const { recipients } = this.state; if (recipients.includes(id)) { const index = recipients.indexOf(id); recipients.splice(index, 1); } else { recipients.push(id); } this.setState({ recipients }); } handleSubmit(e) { e.preventDefault(); const configuration = {}; if (this.state.spotify) { configuration.spotify = { authorization: this.props.spotify_authorization, me: this.props.spotify_me, }; } if (this.state.genius) { configuration.genius = { authorization: this.props.genius_authorization, me: this.props.genius_me, }; } if (this.state.lastfm) { configuration.lastfm = { authorization: this.props.lastfm_authorization, me: this.props.lastfm_me, }; } if (this.state.ui) { configuration.ui = this.props.ui; } for (const recipient of this.state.recipients) { this.props.pusherActions.deliverMessage( recipient, 'share_configuration_received', configuration, ); } window.history.back(); } render() { const connections = []; for (const 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 = (
{ connections.map((connection, index) => ( )) }
); } else { var recipients = (
No peer connections
); } return (

Share configuration

Push your authorizations and interface settings to another, connected user

this.handleSubmit(e)}>
Recipients
{recipients}
Configurations
{this.props.spotify_me && this.props.spotify_authorization ? ( ) : null} {this.props.lastfm_me && this.props.lastfm_authorization ? ( ) : null} {this.props.genius_me && this.props.genius_authorization ? ( ) : null}
{this.state.recipients.length > 0 ? : }
); } } const mapStateToProps = (state, ownProps) => ({ 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, ui: state.ui, connection_id: state.pusher.connection_id, connections: state.pusher.connections, }); const mapDispatchToProps = (dispatch) => ({ pusherActions: bindActionCreators(pusherActions, dispatch), uiActions: bindActionCreators(uiActions, dispatch), }); export default connect(mapStateToProps, mapDispatchToProps)(ShareConfiguration);