import { html, Component } from "../lib/index.js"; const defaultParams = { name: "", host: "", port: 6697, nickname: "", username: "", realname: "", pass: "", }; export default class NetworkForm extends Component { prevParams = null; state = { ...defaultParams, autojoin: true, }; constructor(props) { super(props); this.prevParams = { ...defaultParams }; this.handleInput = this.handleInput.bind(this); this.handleSubmit = this.handleSubmit.bind(this); if (props.params) { Object.keys(defaultParams).forEach((k) => { if (props.params[k] !== undefined) { this.state[k] = props.params[k]; this.prevParams[k] = props.params[k]; } }); } } 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 = {}; Object.keys(defaultParams).forEach((k) => { if (!this.props.isNew && this.prevParams[k] == this.state[k]) { return; } if (this.props.isNew && defaultParams[k] == this.state[k]) { return; } params[k] = this.state[k]; }); let autojoin = this.state.autojoin ? this.props.autojoin : null; this.props.onSubmit(params, autojoin); } render() { let removeNetwork = null; if (!this.props.isNew) { removeNetwork = html` `; } let autojoin = null; if (this.props.autojoin) { autojoin = html`

`; } return html`


${autojoin}
Advanced options












${removeNetwork} ${" "}
`; } }