import React, { Component } from 'react'; import { connect } from 'react-redux'; import { Alert, Card, CardHeader, CardBlock, FormGroup, Progress, Label, Input } from 'reactstrap'; import { initialize } from '..'; import { SOCKET_STATE } from '../actions/socket'; const getURI = (uri, password) => ({ uri, password }); class ConnectionOverlay extends Component { constructor() { super(); this.connect = this.connect.bind(this); const uri = localStorage.getItem("autoconnect"); const password = localStorage.getItem("password"); this.state = { uri: uri || "ws://127.0.0.1:8412", password, autoconnect: !!uri }; if (uri) { initialize(getURI(this.state.uri, this.state.password)); } } connect() { if (this.state.autoconnect) { localStorage.setItem("autoconnect", this.state.uri); localStorage.setItem("password", this.state.password); } initialize(getURI(this.state.uri, this.state.password)); } render() { const { socket } = this.props; if (socket.state === SOCKET_STATE.CONNECTED) { return null; } if (socket.state === SOCKET_STATE.CONNECTING) { return (
Connect to synapse

Connecting...

); } const { uri, password, autoconnect } = this.state; return (
Connect to synapse {socket.reason && {socket.reason}} e.keyCode === 13 && this.connect()} onChange={e => this.setState({ uri: e.target.value })} /> e.keyCode === 13 && this.connect()} onChange={e => this.setState({ password: e.target.value })} />
); } } export default connect(state => ({ socket: state.socket }))(ConnectionOverlay);