Files
vue-chat-layer/app/components/Chat/MentionPopup.vue
Jakub Zych 5d581539b3 feat: port the chat store, realtime client and components
- realtime.ts: the page's one Centrifuge client, setRealtimeAuth, onUserEvent for user:{me} events the chat does not handle
- chatEvents, chatFormat, chatText, chatUnread, format, media, tabs ported; copy passed in localized
- useChat over useState: channels with join and leave, DMs, member list, unread and mention counts, read marks, typing, presence, polling fallback
- ChatPanel, ChatHeader, ChatMessage, ChatDmList, ChatMemberPicker, ChatMentionPopup, ChatAvatar, ChatIcon, ChatNotices
- EN and PL strings
2026-10-31 13:52:56 +01:00

39 lines
1.5 KiB
Vue

<script setup lang="ts">
// The listbox of the composer's mention combobox. The textarea keeps focus;
// it points at the active option through aria-activedescendant, so every
// option has a stable id. Options are picked with mousedown so the textarea
// never loses focus.
import type { ChatMember } from '../../lib/types'
import { fullName } from '../../lib/chatFormat'
defineProps<{ id: string; options: ChatMember[]; active: number; query: string }>()
const emit = defineEmits<{ pick: [member: ChatMember]; hover: [index: number] }>()
const { t } = useI18n()
/** The id of option i; the composer builds the same id for aria-activedescendant. */
function optionId(listId: string, i: number): string {
return `${listId}-opt-${i}`
}
</script>
<template>
<ul :id="id" class="chat-pop chat-mention-pop" role="listbox" :aria-label="t('chat.mention.label')">
<li v-if="!options.length" class="chat-pop-empty" role="option" aria-disabled="true" aria-selected="false">{{ t('chat.mention.none', { q: query }) }}</li>
<li
v-for="(m, i) in options"
:id="optionId(id, i)"
:key="m.id"
class="chat-pop-option"
:class="{ 'is-active': i === active }"
role="option"
:aria-selected="i === active ? 'true' : 'false'"
@mousedown.prevent="emit('pick', m)"
@mousemove="i !== active && emit('hover', i)"
>
<ChatAvatar :user-id="m.id" :member="m" :size="24" />
<span class="chat-pop-name">{{ fullName(m) }}</span>
<span class="chat-pop-meta">@{{ m.handle }}</span>
</li>
</ul>
</template>