diff --git a/components/app.js b/components/app.js index 0a4be12..1640cbd 100644 --- a/components/app.js +++ b/components/app.js @@ -883,7 +883,13 @@ export default class App extends Component { } } if (!bouncerNetID) { - // TODO: open dialog to create network if bouncer + // Open dialog to create network if bouncer + let client = this.clients.values().next().value; + if (client && client.enabledCaps["soju.im/bouncer-networks"]) { + event.preventDefault(); + let params = { host: url.host }; + this.openDialog("network", { params }); + } return; } @@ -1364,13 +1370,15 @@ export default class App extends Component { let dialog = null; switch (this.state.dialog) { case "network": - let title = this.state.dialogData ? "Edit network" : "Add network"; + let isNew = !!(!this.state.dialogData || !this.state.dialogData.id); + let title = isNew ? "Add network" : "Edit network"; dialog = html` <${Dialog} title=${title} onDismiss=${this.dismissDialog}> <${NetworkForm} onSubmit=${this.handleNetworkSubmit} onRemove=${this.handleNetworkRemove} params=${this.state.dialogData ? this.state.dialogData.params : null} + isNew=${isNew} /> `; diff --git a/components/network-form.js b/components/network-form.js index 6cf8f9f..dd41b94 100644 --- a/components/network-form.js +++ b/components/network-form.js @@ -14,7 +14,6 @@ export default class NetworkForm extends Component { prevParams = null; state = { ...defaultParams, - isNew: true, }; constructor(props) { @@ -25,8 +24,6 @@ export default class NetworkForm extends Component { this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); - this.state.isNew = !props.params; - if (props.params) { Object.keys(defaultParams).forEach((k) => { if (props.params[k] !== undefined) { @@ -48,7 +45,10 @@ export default class NetworkForm extends Component { let params = {}; Object.keys(defaultParams).forEach((k) => { - if (this.prevParams[k] == this.state[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]; @@ -59,7 +59,7 @@ export default class NetworkForm extends Component { render() { let removeNetwork = null; - if (!this.state.isNew) { + if (!this.props.isNew) { removeNetwork = html` `;