import { html, Component } from "/lib/index.js";
export default class Connect extends Component {
state = {
serverURL: "",
serverPass: "",
nick: "",
password: "",
rememberMe: false,
username: "",
realname: "",
autojoin: "",
};
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
if (props.params) {
this.state = {
...this.state,
serverURL: props.params.url || "",
nick: props.params.nick || "",
rememberMe: props.params.autoconnect || false,
username: props.params.username || "",
realname: props.params.realname || "",
autojoin: (props.params.autojoin || []).join(","),
};
}
}
handleChange(event) {
var target = event.target;
var value = target.type == "checkbox" ? target.checked : target.value;
this.setState({ [target.name]: value });
}
handleSubmit(event) {
event.preventDefault();
if (this.props.disabled) {
return;
}
var params = {
url: this.state.serverURL,
pass: this.state.serverPass,
nick: this.state.nick,
autoconnect: this.state.rememberMe,
username: this.state.username || this.state.nick,
realname: this.state.realname || this.state.nick,
saslPlain: null,
autojoin: [],
};
if (this.state.password) {
params.saslPlain = {
username: params.username,
password: this.state.password,
};
}
this.state.autojoin.split(",").forEach(function(ch) {
ch = ch.trim();
if (!ch) {
return;
}
params.autojoin.push(ch);
});
this.props.onSubmit(params);
}
render() {
var rememberMe = null;
if (window.localStorage) {
rememberMe = html`
`;
}
return html`