// eslint-disable-next-line const preact = require('preact'); const { Component } = require('preact') const { connect } = require('preact-redux'); const { postData } = require('../utils'); const addState = connect( (state) => { const { ws } = state; function submitLogin(name, password) { postData('/login', { name, password }) .then(data => ws.connect()) .catch(error => console.error(error)); } function submitRegister(name, password, code) { postData('/register', { name, password, code }) .then(data => ws.connect()) .catch(error => console.error(error)); } return { submitLogin, submitRegister, } }, ); class Login extends Component { constructor(props) { super(props); this.state = { name: '', password: '', code: ''}; this.nameInput = this.nameInput.bind(this); this.passwordInput = this.passwordInput.bind(this); this.codeInput = this.codeInput.bind(this); this.loginSubmit = this.loginSubmit.bind(this); this.registerSubmit = this.registerSubmit.bind(this); } nameInput(event) { this.setState({ name: event.target.value }); } passwordInput(event) { this.setState({ password: event.target.value }); } codeInput(event) { this.setState({ code: event.target.value }); } loginSubmit(event) { event.preventDefault(); console.log(this.state); this.props.submitLogin(this.state.name, this.state.password); this.setState({ name: '', password: '' }); } registerSubmit(event) { event.preventDefault(); this.props.submitRegister(this.state.name, this.state.password, this.state.code); console.log(this.state); this.setState({ name: '', password: '', code: ''}); } render() { return (

mnml.gg

); } } module.exports = addState(Login);