hardlounge/client/components/ChannelWrapper.vue
2019-11-25 20:13:17 +02:00

74 lines
1.6 KiB
Vue

<template>
<!-- TODO: move closed style to it's own class -->
<div
v-if="isChannelVisible"
ref="element"
:class="[
'chan',
channel.type,
{active: activeChannel && channel === activeChannel.channel},
{'parted-channel': channel.type === 'channel' && channel.state === 0},
]"
:aria-label="getAriaLabel()"
:title="getAriaLabel()"
:data-name="channel.name"
:aria-controls="'#chan-' + channel.id"
:aria-selected="activeChannel && channel === activeChannel.channel"
:style="channel.closed ? {transition: 'none', opacity: 0.4} : null"
role="tab"
@click="click"
@contextmenu.prevent="openContextMenu"
>
<slot :network="network" :channel="channel" :activeChannel="activeChannel" />
</div>
</template>
<script>
import isChannelCollapsed from "../js/helpers/isChannelCollapsed";
export default {
name: "ChannelWrapper",
props: {
network: Object,
channel: Object,
},
computed: {
activeChannel() {
return this.$store.state.activeChannel;
},
isChannelVisible() {
return !isChannelCollapsed(this.network, this.channel);
},
},
methods: {
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;
},
click() {
this.$root.switchToChannel(this.channel);
},
openContextMenu(event) {
this.$root.$emit("contextmenu:channel", {
event: event,
channel: this.channel,
network: this.network,
});
},
},
};
</script>