2021-03-08 12:15:04 -05:00
|
|
|
import { html, Component } from "../lib/index.js";
|
|
|
|
|
2021-03-09 13:10:22 -05:00
|
|
|
const defaultParams = {
|
|
|
|
name: "",
|
|
|
|
host: "",
|
|
|
|
port: 6697,
|
|
|
|
nickname: "",
|
|
|
|
username: "",
|
|
|
|
realname: "",
|
|
|
|
pass: "",
|
|
|
|
};
|
|
|
|
|
2021-03-08 12:15:04 -05:00
|
|
|
export default class NetworkForm extends Component {
|
2021-03-09 13:10:22 -05:00
|
|
|
prevParams = null;
|
2021-03-08 12:15:04 -05:00
|
|
|
state = {
|
2021-03-09 13:10:22 -05:00
|
|
|
...defaultParams,
|
2021-11-07 13:47:49 -05:00
|
|
|
autojoin: true,
|
2021-03-08 12:15:04 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2021-03-09 13:10:22 -05:00
|
|
|
this.prevParams = { ...defaultParams };
|
|
|
|
|
2023-01-10 09:05:57 -05:00
|
|
|
this.handleInput = this.handleInput.bind(this);
|
2021-03-08 12:15:04 -05:00
|
|
|
this.handleSubmit = this.handleSubmit.bind(this);
|
2021-03-09 13:10:22 -05:00
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-03-08 12:15:04 -05:00
|
|
|
}
|
|
|
|
|
2023-01-10 09:05:57 -05:00
|
|
|
handleInput(event) {
|
2021-06-10 12:11:11 -04:00
|
|
|
let target = event.target;
|
2024-10-13 18:56:18 -04:00
|
|
|
let value = target.type === "checkbox" ? target.checked : target.value;
|
2021-03-08 12:15:04 -05:00
|
|
|
this.setState({ [target.name]: value });
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSubmit(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let params = {};
|
2021-03-09 13:10:22 -05:00
|
|
|
Object.keys(defaultParams).forEach((k) => {
|
2024-10-13 18:56:18 -04:00
|
|
|
if (!this.props.isNew && this.prevParams[k] === this.state[k]) {
|
2021-10-13 10:40:34 -04:00
|
|
|
return;
|
|
|
|
}
|
2024-10-13 18:56:18 -04:00
|
|
|
if (this.props.isNew && defaultParams[k] === this.state[k]) {
|
2021-03-09 13:10:22 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
params[k] = this.state[k];
|
|
|
|
});
|
2021-03-08 12:15:04 -05:00
|
|
|
|
2021-11-07 13:47:49 -05:00
|
|
|
let autojoin = this.state.autojoin ? this.props.autojoin : null;
|
|
|
|
this.props.onSubmit(params, autojoin);
|
2021-03-08 12:15:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2021-06-10 12:11:11 -04:00
|
|
|
let removeNetwork = null;
|
2021-10-13 10:40:34 -04:00
|
|
|
if (!this.props.isNew) {
|
2021-03-09 13:10:22 -05:00
|
|
|
removeNetwork = html`
|
2021-06-10 18:33:22 -04:00
|
|
|
<button type="button" class="danger" onClick=${() => this.props.onRemove()}>
|
2021-03-09 13:10:22 -05:00
|
|
|
Remove network
|
|
|
|
</button>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2021-11-07 13:47:49 -05:00
|
|
|
let autojoin = null;
|
|
|
|
if (this.props.autojoin) {
|
|
|
|
autojoin = html`
|
|
|
|
<label>
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
name="autojoin"
|
|
|
|
checked=${this.state.autojoin}
|
|
|
|
/>
|
|
|
|
Auto-join channel <strong>${this.props.autojoin}</strong>
|
|
|
|
</label>
|
|
|
|
<br/><br/>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2021-03-08 12:15:04 -05:00
|
|
|
return html`
|
2023-01-10 09:05:57 -05:00
|
|
|
<form onInput=${this.handleInput} onSubmit=${this.handleSubmit}>
|
2021-03-08 12:15:04 -05:00
|
|
|
<label>
|
|
|
|
Hostname:<br/>
|
|
|
|
<input type="text" name="host" value=${this.state.host} autofocus required/>
|
|
|
|
</label>
|
|
|
|
<br/><br/>
|
|
|
|
|
2021-11-07 13:47:49 -05:00
|
|
|
${autojoin}
|
|
|
|
|
2021-03-08 12:15:04 -05:00
|
|
|
<details>
|
2021-06-06 06:05:57 -04:00
|
|
|
<summary role="button">Advanced options</summary>
|
2021-03-08 12:15:04 -05:00
|
|
|
|
|
|
|
<br/>
|
|
|
|
|
|
|
|
<label>
|
|
|
|
Port:<br/>
|
|
|
|
<input type="number" name="port" value=${this.state.port}/>
|
|
|
|
</label>
|
|
|
|
<br/><br/>
|
|
|
|
|
2021-03-09 13:10:22 -05:00
|
|
|
<label>
|
|
|
|
Network name:<br/>
|
|
|
|
<input type="text" name="name" value=${this.state.name}/>
|
|
|
|
</label>
|
|
|
|
<br/><br/>
|
|
|
|
|
2021-03-08 12:15:04 -05:00
|
|
|
<label>
|
|
|
|
Nickname:<br/>
|
|
|
|
<input type="username" name="nickname" value=${this.state.nickname}/>
|
|
|
|
</label>
|
|
|
|
<br/><br/>
|
|
|
|
|
|
|
|
<label>
|
|
|
|
Username:<br/>
|
|
|
|
<input type="username" name="username" value=${this.state.username}/>
|
|
|
|
</label>
|
|
|
|
<br/><br/>
|
|
|
|
|
|
|
|
<label>
|
|
|
|
Real name:<br/>
|
|
|
|
<input type="text" name="realname" value=${this.state.realname}/>
|
|
|
|
</label>
|
|
|
|
<br/><br/>
|
|
|
|
|
|
|
|
<label>
|
|
|
|
Server password:<br/>
|
|
|
|
<input type="password" name="pass" value=${this.state.pass} placeholder="None"/>
|
|
|
|
</label>
|
|
|
|
<br/>
|
|
|
|
</details>
|
|
|
|
|
|
|
|
<br/>
|
2021-03-09 13:10:22 -05:00
|
|
|
${removeNetwork}
|
|
|
|
${" "}
|
|
|
|
<button>
|
2021-10-13 10:40:34 -04:00
|
|
|
${this.props.isNew ? "Add network" : "Save network"}
|
2021-03-09 13:10:22 -05:00
|
|
|
</button>
|
2021-03-08 12:15:04 -05:00
|
|
|
</form>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|