mirror of
https://git.sr.ht/~emersion/gamja
synced 2024-11-14 19:25:26 -05:00
c547a32282
This is one of the differences between React and Preact: https://preactjs.com/guide/v10/differences-to-react/#use-oninput-instead-of-onchange Closes: https://todo.sr.ht/~emersion/gamja/128
49 lines
952 B
JavaScript
49 lines
952 B
JavaScript
import { html, Component } from "../lib/index.js";
|
|
|
|
export default class JoinForm extends Component {
|
|
state = {
|
|
channel: "#",
|
|
};
|
|
|
|
constructor(props) {
|
|
super(props);
|
|
|
|
this.handleInput = this.handleInput.bind(this);
|
|
this.handleSubmit = this.handleSubmit.bind(this);
|
|
|
|
if (props.channel) {
|
|
this.state.channel = props.channel;
|
|
}
|
|
}
|
|
|
|
handleInput(event) {
|
|
let target = event.target;
|
|
let value = target.type == "checkbox" ? target.checked : target.value;
|
|
this.setState({ [target.name]: value });
|
|
}
|
|
|
|
handleSubmit(event) {
|
|
event.preventDefault();
|
|
|
|
let params = {
|
|
channel: this.state.channel,
|
|
};
|
|
|
|
this.props.onSubmit(params);
|
|
}
|
|
|
|
render() {
|
|
return html`
|
|
<form onInput=${this.handleInput} onSubmit=${this.handleSubmit}>
|
|
<label>
|
|
Channel:<br/>
|
|
<input type="text" name="channel" value=${this.state.channel} autofocus required/>
|
|
</label>
|
|
<br/>
|
|
|
|
<br/>
|
|
<button>Join</button>
|
|
</form>
|
|
`;
|
|
}
|
|
}
|