mirror of
https://git.sr.ht/~emersion/gamja
synced 2024-11-14 19:25:26 -05:00
Open dialog to create new network on IRC URL click
If we're running under a bouncer and the user clicks a link with a server we aren't connected to yet, open the dialog to add a new network. References: https://todo.sr.ht/~emersion/gamja/71
This commit is contained in:
parent
405bc51c26
commit
3562478946
2 changed files with 16 additions and 8 deletions
|
@ -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}
|
||||
/>
|
||||
</>
|
||||
`;
|
||||
|
|
|
@ -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`
|
||||
<button type="button" class="danger" onClick=${() => this.props.onRemove()}>
|
||||
Remove network
|
||||
|
@ -121,7 +121,7 @@ export default class NetworkForm extends Component {
|
|||
${removeNetwork}
|
||||
${" "}
|
||||
<button>
|
||||
${this.state.isNew ? "Add network" : "Save network"}
|
||||
${this.props.isNew ? "Add network" : "Save network"}
|
||||
</button>
|
||||
</form>
|
||||
`;
|
||||
|
|
Loading…
Reference in a new issue