hardlounge/client/components/JoinChannel.vue

85 lines
1.6 KiB
Vue
Raw Normal View History

<template>
<form
:id="'join-channel-' + channel.id"
class="join-form"
method="post"
action=""
autocomplete="off"
2018-07-12 19:06:17 +00:00
@keydown.esc.prevent="$emit('toggleJoinChannel')"
@submit.prevent="onSubmit"
>
<input
2018-07-12 19:06:17 +00:00
v-model="inputChannel"
2018-07-29 17:57:14 +00:00
v-focus
type="text"
class="input"
name="channel"
placeholder="Channel"
pattern="[^\s]+"
maxlength="200"
title="The channel name may not contain spaces"
required
>
<input
2018-07-12 19:06:17 +00: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"
>
<button
type="submit"
class="btn btn-small"
>Join</button>
</form>
</template>
<script>
2018-07-12 19:06:17 +00:00
import socket from "../js/socket";
export default {
name: "JoinChannel",
2018-07-12 19:06:17 +00:00
directives: {
focus: {
inserted(el) {
el.focus();
},
},
},
props: {
2018-07-23 09:14:35 +00:00
network: Object,
channel: Object,
},
2018-07-12 19:06:17 +00:00
data() {
return {
inputChannel: "",
inputPassword: "",
};
},
methods: {
onSubmit() {
2018-07-23 09:14:35 +00:00
const channelToFind = this.inputChannel.toLowerCase();
const existingChannel = this.network.channels.find((c) => c.name.toLowerCase() === channelToFind);
2018-07-12 19:06:17 +00:00
if (existingChannel) {
const $ = require("jquery");
$(`#sidebar .chan[data-id="${existingChannel.id}"]`).trigger("click");
} else {
socket.emit("input", {
text: `/join ${this.inputChannel} ${this.inputPassword}`,
target: this.channel.id,
});
}
this.inputChannel = "";
this.inputPassword = "";
this.$emit("toggleJoinChannel");
},
},
};
</script>