hardlounge/client/components/ChannelWrapper.vue

86 lines
1.9 KiB
Vue
Raw Normal View History

<template>
<!-- TODO: move closed style to it's own class -->
<div
v-if="isChannelVisible"
2019-08-03 15:03:45 -04:00
ref="element"
2019-02-07 02:24:53 -05:00
:class="[
2019-03-19 09:11:44 -04:00
'chan',
2019-02-07 02:24:53 -05:00
channel.type,
2019-07-17 05:33:59 -04:00
{active: activeChannel && channel === activeChannel.channel},
{'parted-channel': channel.type === 'channel' && channel.state === 0},
2019-02-07 02:24:53 -05:00
]"
:aria-label="getAriaLabel()"
:title="getAriaLabel()"
2019-01-02 07:09:50 -05:00
:data-name="channel.name"
:aria-controls="'#chan-' + channel.id"
:aria-selected="activeChannel && channel === activeChannel.channel"
2019-03-03 14:43:57 -05:00
:style="closed ? {transition: 'none', opacity: 0.4} : null"
role="tab"
2019-10-17 12:56:44 -04:00
@click="click"
2019-11-09 17:21:34 -05:00
@contextmenu.prevent="openContextMenu"
>
2019-07-17 05:33:59 -04:00
<slot :network="network" :channel="channel" :activeChannel="activeChannel" />
</div>
</template>
<script>
2019-03-03 14:43:57 -05:00
import socket from "../js/socket";
2019-11-09 17:21:34 -05:00
import {generateChannelContextMenu} from "../js/helpers/contextMenu.js";
import isChannelCollapsed from "../js/helpers/isChannelCollapsed";
2019-03-03 14:43:57 -05:00
export default {
name: "ChannelWrapper",
props: {
network: Object,
channel: Object,
},
2019-03-03 14:43:57 -05:00
data() {
return {
closed: false,
};
},
computed: {
activeChannel() {
return this.$store.state.activeChannel;
},
isChannelVisible() {
return !isChannelCollapsed(this.network, this.channel);
},
},
methods: {
2019-03-03 14:43:57 -05:00
close() {
this.closed = true;
socket.emit("input", {
target: Number(this.channel.id),
2019-11-02 15:06:34 -04:00
text: "/close",
2019-03-03 14:43:57 -05:00
});
},
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 12:56:44 -04:00
click() {
2019-10-25 17:37:40 -04:00
this.$root.switchToChannel(this.channel);
2019-10-17 12:56:44 -04:00
},
2019-11-09 17:21:34 -05:00
openContextMenu(event) {
const items = generateChannelContextMenu(this.$root, this.channel, this.network);
this.$root.$refs.app.openContextMenu(event, items);
},
},
};
</script>