thelounge/client/components/ChannelWrapper.vue

113 lines
2.8 KiB
Vue
Raw Normal View History

<template>
<!-- TODO: move closed style to it's own class -->
<div
v-if="isChannelVisible"
2019-08-03 21:03:45 +02:00
ref="element"
2019-02-07 08:24:53 +01:00
:class="[
2019-12-04 07:58:23 +01:00
'channel-list-item',
2019-11-26 21:50:40 +01:00
{active: active},
2019-07-17 11:33:59 +02:00
{'parted-channel': channel.type === 'channel' && channel.state === 0},
{'has-draft': channel.pendingMessage},
2021-05-06 03:51:35 +02:00
{'has-unread': channel.unread},
{'has-highlight': channel.highlight},
2019-12-19 14:22:04 +01:00
{
'not-secure':
channel.type === 'lobby' && network.status.connected && !network.status.secure,
},
{'not-connected': channel.type === 'lobby' && !network.status.connected},
{'is-muted': channel.muted},
2019-02-07 08:24:53 +01:00
]"
:aria-label="getAriaLabel()"
:title="getAriaLabel()"
2019-01-02 13:09:50 +01:00
:data-name="channel.name"
2019-12-04 07:58:23 +01:00
:data-type="channel.type"
:aria-controls="'#chan-' + channel.id"
2019-11-26 21:50:40 +01:00
:aria-selected="active"
:style="channel.closed ? {transition: 'none', opacity: 0.4} : undefined"
role="tab"
2019-10-17 18:56:44 +02:00
@click="click"
2019-11-09 23:21:34 +01:00
@contextmenu.prevent="openContextMenu"
>
<slot :network="network" :channel="channel" :active-channel="activeChannel" />
</div>
</template>
<script lang="ts">
2020-03-16 18:58:40 +01:00
import eventbus from "../js/eventbus";
import isChannelCollapsed from "../js/helpers/isChannelCollapsed";
import {ClientNetwork, ClientChan} from "../js/types";
import {computed, defineComponent, PropType} from "vue";
import {useStore} from "../js/store";
import {switchToChannel} from "../js/router";
2019-03-03 20:43:57 +01:00
export default defineComponent({
name: "ChannelWrapper",
props: {
network: {
type: Object as PropType<ClientNetwork>,
required: true,
},
channel: {
type: Object as PropType<ClientChan>,
required: true,
},
active: Boolean,
isFiltering: Boolean,
},
setup(props) {
const store = useStore();
const activeChannel = computed(() => store.state.activeChannel);
const isChannelVisible = computed(
() => props.isFiltering || !isChannelCollapsed(props.network, props.channel)
);
const getAriaLabel = () => {
const extra: string[] = [];
const type = props.channel.type;
if (props.channel.unread > 0) {
if (props.channel.unread > 1) {
extra.push(`${props.channel.unread} unread messages`);
} else {
extra.push(`${props.channel.unread} unread message`);
}
}
if (props.channel.highlight > 0) {
if (props.channel.highlight > 1) {
extra.push(`${props.channel.highlight} mentions`);
} else {
extra.push(`${props.channel.highlight} mention`);
}
}
return `${type}: ${props.channel.name} ${extra.length ? `(${extra.join(", ")})` : ""}`;
};
const click = () => {
if (props.isFiltering) {
return;
}
switchToChannel(props.channel);
};
const openContextMenu = (event: MouseEvent) => {
2020-03-16 18:58:40 +01:00
eventbus.emit("contextmenu:channel", {
2019-11-23 15:26:20 +01:00
event: event,
channel: props.channel,
network: props.network,
2019-11-23 15:26:20 +01:00
});
};
return {
activeChannel,
isChannelVisible,
getAriaLabel,
click,
openContextMenu,
};
},
});
</script>