feat(kaak): match channel sidebar and audio dock reference

This commit is contained in:
illusia committed 2026-10-11 19:20:57 +08:00
1 parent b13bdf1eb2
commit 96d2ebae01
17 files changed
+847 -135

No files matched your search

@@ -1,19 +1,21 @@
<template>
<ul
v-if="tree.length"
v-if="visibleTree.length"
class="ws-voice-channel-tree"
data-ws-part="voice.channel-tree.list"
:data-layout="layout"
role="tree"
aria-label="语音频道 / Voice channels"
>
<VoiceChannelTreeItem
v-for="node in tree"
v-for="node in visibleTree"
:key="node.channel.id"
:node="node"
:depth="0"
:layout="layout"
:current-channel-id="currentChannelId"
:selected-channel-id="selectedChannelId"
:expanded-ids="expandedIds"
:expanded-ids="effectiveExpandedIds"
:avatar-style="avatarStyle"
:avatar-initial="avatarInitial"
:is-speaking="isSpeaking"
@@ -28,19 +30,21 @@
class="ws-voice-channel-tree-empty"
data-ws-part="voice.channel-tree.empty"
role="status"
>无可用语音频道 / No voice channels</div>
>{{ query.trim() ? "没有匹配的频道 / No matching channels" : "无可用语音频道 / No voice channels" }}</div>
</template>
<script setup lang="ts">
import { computed, ref, watch, type CSSProperties } from "vue";
import type { ChannelMember } from "../../composables/useVoiceWebSocket.js";
import type { TreeChannel } from "../../composables/useWebClientChannels.js";
import { buildVoiceChannelTree } from "../../services/voice-channel-tree.js";
import { buildVoiceChannelTree, filterVoiceChannelTree } from "../../services/voice-channel-tree.js";
import VoiceChannelTreeItem from "./VoiceChannelTreeItem.vue";
const props = defineProps<{
channels: readonly TreeChannel[];
currentChannelId?: string;
query?: string;
layout?: "default" | "server-sidebar";
avatarStyle: (name: string, isSelf?: boolean, avatar?: string) => CSSProperties;
avatarInitial: (name: string) => string;
isSpeaking: (member: ChannelMember) => boolean;
@@ -48,8 +52,22 @@ const props = defineProps<{
}>();
const tree = computed(() => buildVoiceChannelTree(props.channels));
const layout = computed(() => props.layout ?? "default");
const query = computed(() => props.query ?? "");
const visibleTree = computed(() => filterVoiceChannelTree(tree.value, query.value));
const selectedChannelId = ref(props.currentChannelId ?? "");
const expandedIds = ref(new Set<string>());
const effectiveExpandedIds = computed(() => {
const result = new Set(expandedIds.value);
if (!query.value.trim()) return result;
const pending = [...visibleTree.value];
while (pending.length) {
const node = pending.pop()!;
if (node.children.length) result.add(node.channel.id);
pending.push(...node.children);
}
return result;
});
watch(() => props.currentChannelId, (channelId) => {
if (channelId) selectedChannelId.value = channelId;
@@ -62,7 +80,7 @@ watch(tree, (nodes) => {
while (pending.length) {
const node = pending.pop()!;
availableIds.add(node.channel.id);
if (node.children.length || node.channel.members.length) expanded.add(node.channel.id);
if (node.children.length || (layout.value === "default" && node.channel.members.length)) expanded.add(node.channel.id);
pending.push(...node.children);
}
for (const id of expanded) if (!availableIds.has(id)) expanded.delete(id);
@@ -85,4 +103,5 @@ function joinChannel(channel: TreeChannel): void {
const emit = defineEmits<{
join: [channel: TreeChannel];
}>();
</script>