2022-02-21 09:44:17 -05:00
|
|
|
import { html, Component } from "../lib/index.js";
|
|
|
|
|
|
|
|
export default class SettingsForm extends Component {
|
|
|
|
state = {};
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2022-06-27 10:34:41 -04:00
|
|
|
this.state.secondsInTimestamps = props.settings.secondsInTimestamps;
|
2022-02-21 09:44:17 -05:00
|
|
|
this.state.bufferEvents = props.settings.bufferEvents;
|
|
|
|
|
|
|
|
this.handleChange = this.handleChange.bind(this);
|
|
|
|
this.handleSubmit = this.handleSubmit.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleChange(event) {
|
|
|
|
let target = event.target;
|
|
|
|
let value = target.type == "checkbox" ? target.checked : target.value;
|
|
|
|
this.setState({ [target.name]: value }, () => {
|
|
|
|
this.props.onChange(this.state);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSubmit(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
this.props.onClose();
|
|
|
|
}
|
|
|
|
|
2022-06-27 11:01:15 -04:00
|
|
|
registerProtocol() {
|
|
|
|
let url = window.location.origin + window.location.pathname + "?open=%s";
|
|
|
|
try {
|
|
|
|
navigator.registerProtocolHandler("irc", url);
|
|
|
|
navigator.registerProtocolHandler("ircs", url);
|
|
|
|
} catch (err) {
|
|
|
|
console.error("Failed to register protocol handler: ", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-21 09:44:17 -05:00
|
|
|
render() {
|
2022-06-27 11:01:15 -04:00
|
|
|
let protocolHandler = null;
|
|
|
|
if (this.props.showProtocolHandler) {
|
|
|
|
protocolHandler = html`
|
|
|
|
<div class="protocol-handler">
|
|
|
|
<div class="left">
|
|
|
|
Set gamja as your default IRC client for this browser.
|
|
|
|
IRC links will be automatically opened here.
|
|
|
|
</div>
|
|
|
|
<div class="right">
|
|
|
|
<button type="button" onClick=${() => this.registerProtocol()}>
|
|
|
|
Enable
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<br/><br/>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2022-02-21 09:44:17 -05:00
|
|
|
return html`
|
|
|
|
<form onChange=${this.handleChange} onSubmit=${this.handleSubmit}>
|
2022-06-27 10:34:41 -04:00
|
|
|
<label>
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
name="secondsInTimestamps"
|
|
|
|
checked=${this.state.secondsInTimestamps}
|
|
|
|
/>
|
|
|
|
Show seconds in time indicator
|
|
|
|
</label>
|
|
|
|
<br/><br/>
|
|
|
|
|
2022-02-21 09:44:17 -05:00
|
|
|
<label>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
name="bufferEvents"
|
|
|
|
value="fold"
|
|
|
|
checked=${this.state.bufferEvents === "fold"}
|
|
|
|
/>
|
|
|
|
Show and fold chat events
|
|
|
|
</label>
|
|
|
|
<br/>
|
|
|
|
<label>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
name="bufferEvents"
|
|
|
|
value="expand"
|
|
|
|
checked=${this.state.bufferEvents === "expand"}
|
|
|
|
/>
|
|
|
|
Show and expand chat events
|
|
|
|
</label>
|
|
|
|
<br/>
|
|
|
|
<label>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
name="bufferEvents"
|
|
|
|
value="hide"
|
|
|
|
checked=${this.state.bufferEvents === "hide"}
|
|
|
|
/>
|
|
|
|
Hide chat events
|
|
|
|
</label>
|
|
|
|
<br/><br/>
|
|
|
|
|
2022-06-27 11:01:15 -04:00
|
|
|
${protocolHandler}
|
|
|
|
|
2022-02-21 09:44:17 -05:00
|
|
|
<button type="button" class="danger" onClick=${() => this.props.onDisconnect()}>
|
|
|
|
Disconnect
|
|
|
|
</button>
|
|
|
|
<button>
|
|
|
|
Close
|
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|