2018-07-06 18:15:15 +00:00
|
|
|
<template>
|
|
|
|
<form
|
|
|
|
:id="'join-channel-' + channel.id"
|
|
|
|
class="join-form"
|
|
|
|
method="post"
|
|
|
|
action=""
|
|
|
|
autocomplete="off"
|
2020-09-30 14:44:07 +00:00
|
|
|
@keydown.esc.prevent="$emit('toggle-join-channel')"
|
2019-02-25 05:38:13 +00:00
|
|
|
@submit.prevent="onSubmit"
|
|
|
|
>
|
2018-07-06 18:15:15 +00:00
|
|
|
<input
|
2018-07-12 19:06:17 +00:00
|
|
|
v-model="inputChannel"
|
2018-07-29 17:57:14 +00:00
|
|
|
v-focus
|
2018-07-06 18:15:15 +00:00
|
|
|
type="text"
|
|
|
|
class="input"
|
|
|
|
name="channel"
|
|
|
|
placeholder="Channel"
|
|
|
|
pattern="[^\s]+"
|
|
|
|
maxlength="200"
|
|
|
|
title="The channel name may not contain spaces"
|
2019-02-25 05:38:13 +00:00
|
|
|
required
|
2019-07-17 09:33:59 +00:00
|
|
|
/>
|
2018-07-06 18:15:15 +00:00
|
|
|
<input
|
2018-07-12 19:06:17 +00:00
|
|
|
v-model="inputPassword"
|
2018-07-06 18:15:15 +00:00
|
|
|
type="password"
|
|
|
|
class="input"
|
|
|
|
name="key"
|
|
|
|
placeholder="Password (optional)"
|
|
|
|
pattern="[^\s]+"
|
|
|
|
maxlength="200"
|
|
|
|
title="The channel password may not contain spaces"
|
2019-02-25 05:38:13 +00:00
|
|
|
autocomplete="new-password"
|
2019-07-17 09:33:59 +00:00
|
|
|
/>
|
|
|
|
<button type="submit" class="btn btn-small">Join</button>
|
2018-07-06 18:15:15 +00:00
|
|
|
</form>
|
|
|
|
</template>
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import {defineComponent, PropType, ref} from "vue";
|
|
|
|
import {switchToChannel} from "../js/router";
|
2018-07-12 19:06:17 +00:00
|
|
|
import socket from "../js/socket";
|
2022-06-19 00:25:21 +00:00
|
|
|
import {useStore} from "../js/store";
|
|
|
|
import {ClientNetwork, ClientChan} from "../js/types";
|
2018-07-12 19:06:17 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
export default defineComponent({
|
2018-07-06 18:15:15 +00:00
|
|
|
name: "JoinChannel",
|
2018-07-12 19:06:17 +00:00
|
|
|
directives: {
|
|
|
|
focus: {
|
2022-06-19 00:25:21 +00:00
|
|
|
mounted: (el: HTMLFormElement) => el.focus(),
|
2018-07-12 19:06:17 +00:00
|
|
|
},
|
|
|
|
},
|
2018-07-06 18:15:15 +00:00
|
|
|
props: {
|
2022-06-19 00:25:21 +00:00
|
|
|
network: {type: Object as PropType<ClientNetwork>, required: true},
|
|
|
|
channel: {type: Object as PropType<ClientChan>, required: true},
|
2018-07-06 18:15:15 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
emits: ["toggle-join-channel"],
|
|
|
|
setup(props, {emit}) {
|
|
|
|
const store = useStore();
|
|
|
|
const inputChannel = ref("");
|
|
|
|
const inputPassword = ref("");
|
|
|
|
|
|
|
|
const onSubmit = () => {
|
|
|
|
const existingChannel = store.getters.findChannelOnCurrentNetwork(inputChannel.value);
|
2018-07-12 19:06:17 +00:00
|
|
|
|
|
|
|
if (existingChannel) {
|
2022-06-19 00:25:21 +00:00
|
|
|
switchToChannel(existingChannel);
|
2018-07-12 19:06:17 +00:00
|
|
|
} else {
|
2022-06-19 00:25:21 +00:00
|
|
|
const chanTypes = props.network.serverOptions.CHANTYPES;
|
|
|
|
let channel = inputChannel.value;
|
2019-10-04 16:56:18 +00:00
|
|
|
|
|
|
|
if (chanTypes && chanTypes.length > 0 && !chanTypes.includes(channel[0])) {
|
|
|
|
channel = chanTypes[0] + channel;
|
|
|
|
}
|
|
|
|
|
2018-07-12 19:06:17 +00:00
|
|
|
socket.emit("input", {
|
2022-06-19 00:25:21 +00:00
|
|
|
text: `/join ${channel} ${inputPassword.value}`,
|
|
|
|
target: props.channel.id,
|
2018-07-12 19:06:17 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
inputChannel.value = "";
|
|
|
|
inputPassword.value = "";
|
|
|
|
emit("toggle-join-channel");
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
inputChannel,
|
|
|
|
inputPassword,
|
|
|
|
onSubmit,
|
|
|
|
};
|
2018-07-12 19:06:17 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
});
|
2018-07-06 18:15:15 +00:00
|
|
|
</script>
|