thelounge/client/components/ChannelWrapper.vue

92 lines
2 KiB
Vue
Raw Normal View History

<template>
<!-- TODO: move closed style to it's own class -->
<div
2019-07-17 11:33:59 +02:00
v-if="
!network.isCollapsed ||
channel.highlight ||
channel.type === 'lobby' ||
(activeChannel && channel === activeChannel.channel)
"
2019-08-03 21:03:45 +02:00
ref="element"
2019-02-07 08:24:53 +01:00
:class="[
2019-03-19 14:11:44 +01:00
'chan',
2019-02-07 08:24:53 +01:00
channel.type,
2019-07-17 11:33:59 +02:00
{active: activeChannel && channel === activeChannel.channel},
{'parted-channel': channel.type === 'channel' && channel.state === 0},
2019-02-07 08:24:53 +01:00
]"
:aria-label="getAriaLabel()"
:title="getAriaLabel()"
:data-id="channel.id"
:data-target="'#chan-' + channel.id"
2019-01-02 13:09:50 +01:00
:data-name="channel.name"
:aria-controls="'#chan-' + channel.id"
:aria-selected="activeChannel && channel === activeChannel.channel"
2019-03-03 20:43:57 +01:00
:style="closed ? {transition: 'none', opacity: 0.4} : null"
role="tab"
2019-10-17 18:56:44 +02:00
@click="click"
>
2019-07-17 11:33:59 +02:00
<slot :network="network" :channel="channel" :activeChannel="activeChannel" />
</div>
</template>
<script>
2019-03-03 20:43:57 +01:00
import socket from "../js/socket";
export default {
name: "ChannelWrapper",
props: {
network: Object,
channel: Object,
activeChannel: Object,
},
2019-03-03 20:43:57 +01:00
data() {
return {
closed: false,
};
},
methods: {
2019-03-03 20:43:57 +01:00
close() {
let cmd = "/close";
if (this.channel.type === "lobby") {
cmd = "/quit";
2019-08-03 21:03:45 +02:00
// eslint-disable-next-line no-alert
2019-08-03 20:48:06 +02:00
if (!confirm(`Are you sure you want to remove ${this.channel.name}?`)) {
2019-03-03 20:43:57 +01:00
return false;
}
}
this.closed = true;
socket.emit("input", {
target: Number(this.channel.id),
text: cmd,
});
},
getAriaLabel() {
const extra = [];
if (this.channel.unread > 0) {
extra.push(`${this.channel.unread} unread`);
}
if (this.channel.highlight > 0) {
extra.push(`${this.channel.highlight} mention`);
}
if (extra.length > 0) {
return `${this.channel.name} (${extra.join(", ")})`;
}
return this.channel.name;
},
2019-10-17 18:56:44 +02:00
click() {
// TODO: Find out why this sometimes throws `uncaught exception: Object`
this.$router.push("chan-" + this.channel.id);
this.$root.closeSidebarIfNeeded();
},
},
};
</script>