thelounge/client/components/JoinChannel.vue

90 lines
1.7 KiB
Vue
Raw Normal View History

<template>
<form
:id="'join-channel-' + channel.id"
class="join-form"
method="post"
action=""
autocomplete="off"
@keydown.esc.prevent="$emit('toggle-join-channel')"
@submit.prevent="onSubmit"
>
<input
2018-07-12 21:06:17 +02:00
v-model="inputChannel"
2018-07-29 19:57:14 +02:00
v-focus
type="text"
class="input"
name="channel"
placeholder="Channel"
pattern="[^\s]+"
maxlength="200"
title="The channel name may not contain spaces"
required
2019-07-17 11:33:59 +02:00
/>
<input
2018-07-12 21:06:17 +02:00
v-model="inputPassword"
type="password"
class="input"
name="key"
placeholder="Password (optional)"
pattern="[^\s]+"
maxlength="200"
title="The channel password may not contain spaces"
autocomplete="new-password"
2019-07-17 11:33:59 +02:00
/>
<button type="submit" class="btn btn-small">Join</button>
</form>
</template>
<script>
2018-07-12 21:06:17 +02:00
import socket from "../js/socket";
export default {
name: "JoinChannel",
2018-07-12 21:06:17 +02:00
directives: {
focus: {
2021-03-29 04:55:35 +02:00
mounted(el) {
2018-07-12 21:06:17 +02:00
el.focus();
},
},
},
props: {
2018-07-23 11:14:35 +02:00
network: Object,
channel: Object,
},
2021-03-29 04:55:35 +02:00
emits: ["toggle-join-channel"],
2018-07-12 21:06:17 +02:00
data() {
return {
inputChannel: "",
inputPassword: "",
};
},
methods: {
onSubmit() {
2019-11-08 00:44:19 +01:00
const existingChannel = this.$store.getters.findChannelOnCurrentNetwork(
this.inputChannel
);
2018-07-12 21:06:17 +02:00
if (existingChannel) {
2019-10-25 23:37:40 +02:00
this.$root.switchToChannel(existingChannel);
2018-07-12 21:06:17 +02:00
} else {
2019-10-04 18:56:18 +02:00
const chanTypes = this.network.serverOptions.CHANTYPES;
let channel = this.inputChannel;
if (chanTypes && chanTypes.length > 0 && !chanTypes.includes(channel[0])) {
channel = chanTypes[0] + channel;
}
2018-07-12 21:06:17 +02:00
socket.emit("input", {
2019-10-04 18:56:18 +02:00
text: `/join ${channel} ${this.inputPassword}`,
2018-07-12 21:06:17 +02:00
target: this.channel.id,
});
}
this.inputChannel = "";
this.inputPassword = "";
this.$emit("toggle-join-channel");
2018-07-12 21:06:17 +02:00
},
},
};
</script>