mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
refactor: extract client join and chat panels and fit narrow forms
This commit is contained in:
1 parent
a2f91e606f
commit
a416e36bd1
7 files changed
+337
-233
No files matched your search
@@ -0,0 +1,72 @@
|
||||
<template>
|
||||
<section :class="['chat-panel', { 'mobile-section-hidden': mobileHidden }]" data-ws-part="voice.chat">
|
||||
<div class="chat-tabs" data-ws-part="voice.chat.tabs" role="tablist" :aria-label="t('chatTabs')">
|
||||
<button type="button" data-ws-part="voice.chat.tab" :data-ws-state="chatTab === 'channel' ? 'active' : 'idle'" :class="{ active: chatTab === 'channel' }" @click="chatTab = 'channel'"><Icon name="hash" :size="15" /> {{ currentChannelName }}</button>
|
||||
<button type="button" data-ws-part="voice.chat.tab" :data-ws-state="chatTab === 'server' ? 'active' : 'idle'" :class="{ active: chatTab === 'server' }" @click="chatTab = 'server'"><Icon name="server" :size="15" /> {{ t('serverChat') }}</button>
|
||||
<button v-for="conversation in privateConversations" :key="conversation.key" type="button" data-ws-part="voice.chat.tab" :data-ws-state="chatTab === 'private' && privateConversationKey === conversation.key ? 'active' : 'idle'" :class="{ active: chatTab === 'private' && privateConversationKey === conversation.key }" @click="openConversation(conversation)"><Icon name="message" :size="15" /> {{ conversation.name }}</button>
|
||||
<button type="button" data-ws-part="voice.chat.tab" :data-ws-state="chatTab === 'events' ? 'active' : 'idle'" :class="{ active: chatTab === 'events' }" @click="chatTab = 'events'"><Icon name="bell" :size="15" /> {{ t('eventLog') }}</button>
|
||||
</div>
|
||||
<div class="section-heading chat-heading" data-ws-part="voice.chat.heading"><div><span class="section-kicker">{{ chatTabLabel }}</span><h2><Icon :name="chatTab === 'server' ? 'server' : chatTab === 'events' ? 'bell' : chatTab === 'private' ? 'message' : 'hash'" :size="20" /> {{ chatTitle }}</h2></div><span class="section-counter">{{ chatTab === 'events' ? t('eventCount', { count: serverEvents.length }) : t('messageCount', { count: visibleChatMessages.length }) }}</span></div>
|
||||
<div ref="chatListEl" class="message-list" data-ws-part="voice.chat.messages">
|
||||
<div v-if="chatTab === 'events'">
|
||||
<article v-for="event in serverEvents" :key="event.id" class="event-row" data-ws-part="voice.chat.event"><time>{{ formatTime(event.timestamp) }}</time><span>{{ event.message }}</span></article>
|
||||
<div v-if="!serverEvents.length" class="chat-empty" data-ws-part="voice.chat.empty" data-ws-state="events-empty"><div class="chat-empty-icon"><Icon name="bell" :size="24" /></div><strong>{{ t('noEvents') }}</strong><span>{{ t('noEventsLead') }}</span></div>
|
||||
</div>
|
||||
<div v-else-if="!visibleChatMessages.length" class="chat-empty" data-ws-part="voice.chat.empty" data-ws-state="messages-empty"><strong>{{ chatTab === 'private' ? t('privateChatStart') : t('chatStart') }}</strong><span>{{ chatTab === 'private' ? t('privateChatStartLead') : t('chatStartLead') }}</span></div>
|
||||
<template v-for="message in visibleChatMessages" :key="message.id">
|
||||
<article v-if="chatTab !== 'events'" :class="['message-row', { mine: message.isSelf }]" data-ws-part="voice.chat.message" :data-ws-state="message.isSelf ? 'mine' : 'other'">
|
||||
<div class="message-avatar" data-ws-part="voice.chat.message-avatar" :style="avatarStyle(message.invokerName, message.isSelf, messageAvatar(message))">{{ messageAvatar(message) ? '' : avatarInitial(message.invokerName) }}</div>
|
||||
<div class="message-body" data-ws-part="voice.chat.message-body"><div class="message-meta"><strong>{{ message.isSelf ? t('you') : message.invokerName }}</strong><time>{{ formatTime(message.timestamp) }}</time></div><div class="message-bubble" data-ws-part="voice.chat.message-bubble">{{ message.message }}</div></div>
|
||||
</article>
|
||||
</template>
|
||||
</div>
|
||||
<form v-if="chatTab !== 'events'" class="message-composer" data-ws-part="voice.chat.composer" @submit.prevent="submitMessage">
|
||||
<input v-model="messageDraft" maxlength="500" :placeholder="chatPlaceholder" :aria-label="t('send')" />
|
||||
<button class="send-button" type="submit" :disabled="!canSendChat || !messageDraft.trim()" :title="t('send')"><Icon name="send" :size="18" /></button>
|
||||
</form>
|
||||
<p v-if="chatStatus" class="chat-status" data-ws-part="voice.chat.status" role="status">{{ chatStatus }}</p>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { CSSProperties } from "vue";
|
||||
import Icon from "../Icon.vue";
|
||||
import type { useWebClientChat } from "../../composables/useWebClientChat.js";
|
||||
import type { ChatMessage, ServerEvent } from "../../composables/useVoiceWebSocket.js";
|
||||
|
||||
type ChatPanelModel = Pick<ReturnType<typeof useWebClientChat>,
|
||||
| "tab" | "privateConversationKey" | "canSend" | "status" | "messageDraft"
|
||||
| "listElement" | "conversations" | "visibleMessages" | "tabLabel" | "title"
|
||||
| "placeholder" | "openConversation" | "submitMessage"
|
||||
>;
|
||||
|
||||
const props = defineProps<{
|
||||
model: ChatPanelModel;
|
||||
t: (key: string, variables?: Record<string, string | number>) => string;
|
||||
currentChannelName: string;
|
||||
mobileHidden: boolean;
|
||||
serverEvents: readonly ServerEvent[];
|
||||
avatarStyle: (name: string, isSelf?: boolean, avatar?: string) => CSSProperties;
|
||||
avatarInitial: (name: string) => string;
|
||||
messageAvatar: (message: ChatMessage) => string;
|
||||
formatTime: (timestamp: number) => string;
|
||||
}>();
|
||||
|
||||
// The page owns one stable controller across room and mobile view changes.
|
||||
// Keep its list ref attached to the rendered scroller, including unmount cleanup.
|
||||
const {
|
||||
tab: chatTab,
|
||||
privateConversationKey,
|
||||
canSend: canSendChat,
|
||||
status: chatStatus,
|
||||
messageDraft,
|
||||
listElement: chatListEl,
|
||||
conversations: privateConversations,
|
||||
visibleMessages: visibleChatMessages,
|
||||
tabLabel: chatTabLabel,
|
||||
title: chatTitle,
|
||||
placeholder: chatPlaceholder,
|
||||
openConversation,
|
||||
submitMessage,
|
||||
} = props.model;
|
||||
</script>
|
||||
@@ -0,0 +1,77 @@
|
||||
<template>
|
||||
<form class="join-form" data-ws-part="home.form" @submit.prevent="emit('connect')">
|
||||
<div v-if="accessMode === 'open'" class="field-grid target-fields" data-ws-part="home.server-target">
|
||||
<label class="field-label" data-ws-part="home.field-label" for="server-address"><span>{{ t('serverAddress') }}</span><div class="field-wrap" data-ws-part="home.field"><Icon name="server" :size="17" /><input id="server-address" v-model="serverHost" autocomplete="url" :placeholder="t('serverAddressPlaceholder')" /></div></label>
|
||||
<label class="field-label" data-ws-part="home.field-label" for="server-port"><span>{{ t('serverPort') }}</span><div class="field-wrap" data-ws-part="home.field"><Icon name="hash" :size="17" /><input id="server-port" v-model="serverPort" inputmode="numeric" type="text" maxlength="5" :placeholder="t('serverPortPlaceholder')" /></div></label>
|
||||
</div>
|
||||
<div v-if="openTargetPrefillBlocked" class="notice warning-notice" data-ws-part="home.notice" data-ws-state="target-prefill-blocked"><span class="notice-symbol">i</span><span>{{ t('openTargetDefaultNotPrefilled') }}</span></div>
|
||||
<div v-if="accelerationRelays.length" class="acceleration-choice" data-ws-part="home.relay-choice"><div class="acceleration-copy" data-ws-part="home.relay-choice.copy"><strong>{{ t('relayAcceleration') }}</strong><small>{{ t('relayAccelerationHint') }}</small></div><select v-model="accelerationRelayId" :aria-label="t('relayAcceleration')"><option value="">{{ t('directConnection') }}</option><option v-for="relay in accelerationRelays" :key="relay.id" :value="relay.id">{{ relay.name }}</option></select></div>
|
||||
<div v-if="accessMode === 'open' && (favoriteServers.length || recentServers.length)" class="local-servers" data-ws-part="home.server-history">
|
||||
<div v-if="favoriteServers.length" class="local-server-group" data-ws-part="home.server-history.group" data-ws-state="favorite"><span>{{ t('favoriteServers') }}</span><button v-for="favorite in favoriteServers" :key="favorite.id" type="button" @click="emit('selectServer', favorite.address, favorite.nickname)">{{ favorite.label }}</button></div>
|
||||
<div v-if="recentServers.length" class="local-server-group" data-ws-part="home.server-history.group" data-ws-state="recent"><span>{{ t('recentServers') }}</span><button v-for="recent in recentServers" :key="recent.id" type="button" @click="emit('selectServer', recent.address, recent.nickname)">{{ recent.address }}</button></div>
|
||||
</div>
|
||||
<button v-if="accessMode === 'open' && serverHost.trim()" type="button" class="favorite-toggle" data-ws-part="home.favorite-toggle" @click="emit('toggleFavorite')">{{ isFavorite ? t('removeFavorite') : t('saveFavorite') }}</button>
|
||||
|
||||
<template v-if="accessMode === 'open'">
|
||||
<label class="field-label" data-ws-part="home.field-label" for="server-password">{{ t('serverPassword') }} <span>{{ t('optional') }}</span></label>
|
||||
<div class="field-wrap" data-ws-part="home.field"><Icon name="lock" :size="17" /><input id="server-password" v-model="serverPassword" type="password" autocomplete="off" :placeholder="t('optionalPassword')" /></div>
|
||||
</template>
|
||||
|
||||
<label class="field-label" data-ws-part="home.field-label" for="nickname">{{ t('nickname') }}</label>
|
||||
<div class="field-wrap" data-ws-part="home.field">
|
||||
<Icon name="users" :size="17" />
|
||||
<input id="nickname" v-model="nickname" autocomplete="nickname" maxlength="30" :placeholder="t('nicknamePlaceholder')" autofocus />
|
||||
</div>
|
||||
|
||||
<label class="field-label" data-ws-part="home.field-label" for="channel">{{ t('targetChannel') }} <span>{{ t('optional') }}</span></label>
|
||||
<div class="field-wrap" data-ws-part="home.field">
|
||||
<Icon name="hash" :size="17" />
|
||||
<input id="channel" v-model="channel" :placeholder="t('emptyDefault')" @keyup.enter="emit('connect')" />
|
||||
</div>
|
||||
|
||||
<details class="identity-options" data-ws-part="home.identity"><summary>{{ t('identityOptions') }}</summary><div class="identity-controls"><label class="remember-identity"><input v-model="rememberIdentity" type="checkbox" /><span><strong>{{ t('rememberIdentity') }}</strong><small>{{ t('rememberIdentityHint') }}</small></span></label><div class="identity-actions" data-ws-part="home.identity-actions"><button type="button" class="identity-action-button" data-ws-part="home.identity-import.open" @click="emit('importIdentity')">{{ t('identityImport') }}</button><button type="button" class="identity-action-button" data-ws-part="home.identity-export.button" :disabled="identityExportBusy || !rememberIdentity || !hasIdentity" @click="emit('exportIdentity')">{{ t('identityExport') }}</button></div></div></details><p v-if="rememberIdentity" class="identity-warning">{{ t('rememberIdentityConcurrentWarning') }}</p>
|
||||
|
||||
<button class="primary-button connect-button" data-ws-part="home.connect" :disabled="joinDisabled" type="submit">
|
||||
<span v-if="connecting" class="button-spinner"></span>
|
||||
<span>{{ connecting ? t('connecting') : t('enterVoice') }}</span>
|
||||
<Icon v-if="!connecting" name="chevron-right" :size="17" />
|
||||
</button>
|
||||
<button v-if="connecting" type="button" class="cancel-connect-button" @click="emit('disconnect')">{{ t('cancel') }}</button>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import Icon from "../Icon.vue";
|
||||
import type { FavoriteServer, RecentServer } from "../../services/local-persistence.js";
|
||||
|
||||
const serverHost = defineModel<string>("serverHost", { required: true });
|
||||
const serverPort = defineModel<string>("serverPort", { required: true });
|
||||
const serverPassword = defineModel<string>("serverPassword", { required: true });
|
||||
const nickname = defineModel<string>("nickname", { required: true });
|
||||
const channel = defineModel<string>("channel", { required: true });
|
||||
const rememberIdentity = defineModel<boolean>("rememberIdentity", { required: true });
|
||||
const accelerationRelayId = defineModel<string>("accelerationRelayId", { required: true });
|
||||
|
||||
defineProps<{
|
||||
accessMode: "fixed" | "open";
|
||||
openTargetPrefillBlocked: boolean;
|
||||
accelerationRelays: ReadonlyArray<{ id: string; name: string }>;
|
||||
favoriteServers: readonly FavoriteServer[];
|
||||
recentServers: readonly RecentServer[];
|
||||
isFavorite: boolean;
|
||||
identityExportBusy: boolean;
|
||||
hasIdentity: boolean;
|
||||
connecting: boolean;
|
||||
joinDisabled: boolean;
|
||||
t: (key: string, variables?: Record<string, string | number>) => string;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
connect: [];
|
||||
disconnect: [];
|
||||
importIdentity: [];
|
||||
exportIdentity: [];
|
||||
toggleFavorite: [];
|
||||
selectServer: [address: string, nickname?: string];
|
||||
}>();
|
||||
</script>
|
||||
Reference in new issue
Block a user