2021-07-04 15:28:45 -04:00
|
|
|
import { html, Component, createRef } from "../lib/index.js";
|
2021-11-29 07:38:07 -05:00
|
|
|
import linkify from "../lib/linkify.js";
|
2020-06-18 08:23:08 -04:00
|
|
|
|
2021-03-09 07:25:31 -05:00
|
|
|
export default class ConnectForm extends Component {
|
2020-06-18 08:23:08 -04:00
|
|
|
state = {
|
2021-05-31 12:04:02 -04:00
|
|
|
url: "",
|
|
|
|
pass: "",
|
2020-06-18 08:23:08 -04:00
|
|
|
nick: "",
|
|
|
|
password: "",
|
|
|
|
rememberMe: false,
|
|
|
|
username: "",
|
|
|
|
realname: "",
|
2021-11-27 06:08:23 -05:00
|
|
|
autojoin: true,
|
2020-06-18 08:23:08 -04:00
|
|
|
};
|
2021-07-04 15:28:45 -04:00
|
|
|
nickInput = createRef();
|
2020-06-18 08:23:08 -04:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.handleChange = this.handleChange.bind(this);
|
|
|
|
this.handleSubmit = this.handleSubmit.bind(this);
|
|
|
|
|
|
|
|
if (props.params) {
|
|
|
|
this.state = {
|
|
|
|
...this.state,
|
2021-05-31 12:04:02 -04:00
|
|
|
url: props.params.url || "",
|
2020-06-18 08:23:08 -04:00
|
|
|
nick: props.params.nick || "",
|
2020-06-24 12:14:46 -04:00
|
|
|
rememberMe: props.params.autoconnect || false,
|
2020-06-18 08:23:08 -04:00
|
|
|
username: props.params.username || "",
|
|
|
|
realname: props.params.realname || "",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleChange(event) {
|
2021-06-10 12:11:11 -04:00
|
|
|
let target = event.target;
|
|
|
|
let value = target.type == "checkbox" ? target.checked : target.value;
|
2020-06-18 08:23:08 -04:00
|
|
|
this.setState({ [target.name]: value });
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSubmit(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
2021-06-06 05:33:00 -04:00
|
|
|
if (this.props.connecting) {
|
2020-06-18 08:23:08 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let params = {
|
2021-05-31 12:04:02 -04:00
|
|
|
url: this.state.url,
|
|
|
|
pass: this.state.pass,
|
2020-06-18 08:23:08 -04:00
|
|
|
nick: this.state.nick,
|
2020-06-24 12:14:46 -04:00
|
|
|
autoconnect: this.state.rememberMe,
|
2021-05-31 11:57:17 -04:00
|
|
|
username: this.state.username,
|
|
|
|
realname: this.state.realname,
|
2020-06-18 08:23:08 -04:00
|
|
|
saslPlain: null,
|
|
|
|
autojoin: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
if (this.state.password) {
|
|
|
|
params.saslPlain = {
|
2021-05-31 12:04:02 -04:00
|
|
|
username: params.username || params.nick,
|
2020-06-18 08:23:08 -04:00
|
|
|
password: this.state.password,
|
|
|
|
};
|
2021-10-12 11:29:56 -04:00
|
|
|
} else if (this.props.auth === "external") {
|
|
|
|
params.saslExternal = true;
|
2020-06-18 08:23:08 -04:00
|
|
|
}
|
|
|
|
|
2021-11-27 06:08:23 -05:00
|
|
|
if (this.state.autojoin) {
|
|
|
|
params.autojoin = this.props.params.autojoin || [];
|
|
|
|
}
|
2020-06-18 08:23:08 -04:00
|
|
|
|
|
|
|
this.props.onSubmit(params);
|
|
|
|
}
|
|
|
|
|
2021-07-04 15:28:45 -04:00
|
|
|
componentDidMount() {
|
|
|
|
if (this.nickInput.current) {
|
|
|
|
this.nickInput.current.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-18 08:23:08 -04:00
|
|
|
render() {
|
2021-06-10 12:11:11 -04:00
|
|
|
let disabled = this.props.connecting;
|
2021-06-06 05:33:00 -04:00
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let serverURL = null;
|
2021-05-31 12:13:44 -04:00
|
|
|
if (!this.props.params || !this.props.params.url) {
|
|
|
|
serverURL = html`
|
|
|
|
<label>
|
|
|
|
Server URL:<br/>
|
2021-07-04 15:51:42 -04:00
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
name="url"
|
|
|
|
value=${this.state.url}
|
|
|
|
disabled=${disabled}
|
|
|
|
inputmode="url"
|
|
|
|
/>
|
2021-05-31 12:13:44 -04:00
|
|
|
</label>
|
|
|
|
<br/><br/>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let status = null;
|
2021-06-06 05:33:00 -04:00
|
|
|
if (this.props.connecting) {
|
|
|
|
status = html`
|
|
|
|
<p>Connecting...</p>
|
|
|
|
`;
|
|
|
|
} else if (this.props.error) {
|
|
|
|
status = html`
|
2021-11-29 07:38:07 -05:00
|
|
|
<p class="error-text">${linkify(this.props.error)}</p>
|
2021-06-06 05:33:00 -04:00
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let auth = null;
|
2021-10-12 11:29:56 -04:00
|
|
|
if (this.props.auth !== "disabled" && this.props.auth !== "external") {
|
2021-06-10 11:40:59 -04:00
|
|
|
auth = html`
|
|
|
|
<label>
|
|
|
|
Password:<br/>
|
|
|
|
<input
|
|
|
|
type="password"
|
|
|
|
name="password"
|
|
|
|
value=${this.state.password}
|
|
|
|
disabled=${disabled}
|
|
|
|
required=${this.props.auth === "mandatory"}
|
|
|
|
placeholder=${this.props.auth !== "mandatory" ? "(optional)" : ""}
|
|
|
|
/>
|
|
|
|
</label>
|
|
|
|
<br/><br/>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2021-11-27 06:08:23 -05:00
|
|
|
let autojoin = null;
|
|
|
|
let channels = this.props.params.autojoin || [];
|
|
|
|
if (channels.length > 0) {
|
|
|
|
let s = channels.length > 1 ? "s" : "";
|
|
|
|
autojoin = html`
|
|
|
|
<label>
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
name="autojoin"
|
|
|
|
checked=${this.state.autojoin}
|
|
|
|
/>
|
|
|
|
Auto-join channel${s} <strong>${channels.join(', ')}</strong>
|
|
|
|
</label>
|
|
|
|
<br/><br/>
|
|
|
|
`;
|
|
|
|
}
|
2021-06-10 12:21:18 -04:00
|
|
|
|
2020-06-18 08:23:08 -04:00
|
|
|
return html`
|
|
|
|
<form onChange=${this.handleChange} onSubmit=${this.handleSubmit}>
|
|
|
|
<h2>Connect to IRC</h2>
|
|
|
|
|
|
|
|
<label>
|
|
|
|
Nickname:<br/>
|
2021-07-04 15:51:42 -04:00
|
|
|
<input
|
|
|
|
type="username"
|
|
|
|
name="nick"
|
|
|
|
value=${this.state.nick}
|
|
|
|
disabled=${disabled}
|
|
|
|
ref=${this.nickInput}
|
|
|
|
required
|
|
|
|
/>
|
2020-06-18 08:23:08 -04:00
|
|
|
</label>
|
|
|
|
<br/><br/>
|
|
|
|
|
2021-06-10 11:40:59 -04:00
|
|
|
${auth}
|
2020-06-18 08:23:08 -04:00
|
|
|
|
2021-11-27 06:08:23 -05:00
|
|
|
${autojoin}
|
2021-06-10 12:21:18 -04:00
|
|
|
|
2021-05-26 12:43:11 -04:00
|
|
|
<label>
|
2021-07-04 15:51:42 -04:00
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
name="rememberMe"
|
|
|
|
checked=${this.state.rememberMe}
|
|
|
|
disabled=${disabled}
|
|
|
|
/>
|
2021-05-26 12:43:11 -04:00
|
|
|
Remember me
|
|
|
|
</label>
|
|
|
|
<br/><br/>
|
2020-06-18 08:23:08 -04:00
|
|
|
|
|
|
|
<details>
|
2021-06-06 06:05:57 -04:00
|
|
|
<summary role="button">Advanced options</summary>
|
2020-06-18 08:23:08 -04:00
|
|
|
|
|
|
|
<br/>
|
|
|
|
|
2021-05-31 12:13:44 -04:00
|
|
|
${serverURL}
|
2020-06-18 08:23:08 -04:00
|
|
|
|
|
|
|
<label>
|
|
|
|
Username:<br/>
|
2021-07-04 15:51:42 -04:00
|
|
|
<input
|
|
|
|
type="username"
|
|
|
|
name="username"
|
|
|
|
value=${this.state.username}
|
|
|
|
disabled=${disabled}
|
|
|
|
placeholder="Same as nickname"
|
|
|
|
/>
|
2020-06-18 08:23:08 -04:00
|
|
|
</label>
|
|
|
|
<br/><br/>
|
|
|
|
|
|
|
|
<label>
|
|
|
|
Real name:<br/>
|
2021-07-04 15:51:42 -04:00
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
name="realname"
|
|
|
|
value=${this.state.realname}
|
|
|
|
disabled=${disabled}
|
|
|
|
placeholder="Same as nickname"
|
|
|
|
/>
|
2020-06-18 08:23:08 -04:00
|
|
|
</label>
|
|
|
|
<br/><br/>
|
|
|
|
|
|
|
|
<label>
|
|
|
|
Server password:<br/>
|
2021-07-04 15:51:42 -04:00
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
name="pass"
|
|
|
|
value=${this.state.pass}
|
|
|
|
disabled=${disabled}
|
|
|
|
placeholder="None"
|
|
|
|
/>
|
2020-06-18 08:23:08 -04:00
|
|
|
</label>
|
|
|
|
<br/><br/>
|
|
|
|
</details>
|
|
|
|
|
|
|
|
<br/>
|
2021-06-06 05:33:00 -04:00
|
|
|
<button disabled=${disabled}>Connect</button>
|
|
|
|
|
|
|
|
${status}
|
2020-06-18 08:23:08 -04:00
|
|
|
</form>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|