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
This commit is contained in:
94
app/components/Chat/MemberPicker.vue
Normal file
94
app/components/Chat/MemberPicker.vue
Normal file
@@ -0,0 +1,94 @@
|
||||
<script setup lang="ts">
|
||||
// The new-message dialog: a native modal listing the other members.
|
||||
// Picking one opens (or creates) the DM; Esc, the backdrop and Close close
|
||||
// it and return focus to the opener.
|
||||
import { filterMembers, fullName } from '../../lib/chatFormat'
|
||||
|
||||
const emit = defineEmits<{ started: [conversationId: number] }>()
|
||||
const { t } = useI18n()
|
||||
const chat = useChat()
|
||||
const uid = useId()
|
||||
const dialog = ref<HTMLDialogElement | null>(null)
|
||||
const search = ref<HTMLInputElement | null>(null)
|
||||
const q = ref('')
|
||||
const busy = ref(false)
|
||||
let opener: HTMLElement | null = null
|
||||
let picked = false
|
||||
|
||||
const others = computed(() => filterMembers(chat.members.values(), '', chat.userId))
|
||||
const results = computed(() => filterMembers(chat.members.values(), q.value, chat.userId))
|
||||
|
||||
function open() {
|
||||
opener = document.activeElement instanceof HTMLElement ? document.activeElement : null
|
||||
picked = false
|
||||
q.value = ''
|
||||
chat.dmError = ''
|
||||
void chat.loadMembers()
|
||||
dialog.value?.showModal()
|
||||
void nextTick(() => search.value?.focus())
|
||||
}
|
||||
|
||||
function close() {
|
||||
dialog.value?.close()
|
||||
}
|
||||
|
||||
function onClose() {
|
||||
if (!picked) opener?.focus()
|
||||
opener = null
|
||||
}
|
||||
|
||||
function onBackdrop(e: MouseEvent) {
|
||||
if (e.target === dialog.value) close()
|
||||
}
|
||||
|
||||
async function pick(id: number) {
|
||||
if (busy.value) return
|
||||
busy.value = true
|
||||
try {
|
||||
const conversationId = await chat.startDm(id)
|
||||
if (conversationId === null) return
|
||||
picked = true
|
||||
close()
|
||||
emit('started', conversationId)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ open })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<dialog ref="dialog" class="chat-dialog" :aria-labelledby="`chat-picker-h-${uid}`" @close="onClose" @click="onBackdrop">
|
||||
<div class="chat-dialog-head">
|
||||
<h2 :id="`chat-picker-h-${uid}`" class="chat-dialog-title">{{ t('chat.dm.new') }}</h2>
|
||||
<button class="chat-icon-btn" type="button" :aria-label="t('chat.close')" @click="close"><ChatIcon name="close" /></button>
|
||||
</div>
|
||||
<div class="chat-field">
|
||||
<label :for="`chat-picker-q-${uid}`">{{ t('chat.picker.to') }}</label>
|
||||
<input :id="`chat-picker-q-${uid}`" ref="search" v-model="q" type="text" autocomplete="off" :placeholder="t('chat.picker.placeholder')" />
|
||||
</div>
|
||||
<p v-if="chat.dmError" class="chat-error" role="alert">{{ t(`chat.${chat.dmError}`) }}</p>
|
||||
<div class="chat-picker-results">
|
||||
<div v-if="chat.membersState === 'loading' && !chat.members.size" class="chat-skeletons" aria-busy="true" :aria-label="t('chat.loading')">
|
||||
<div class="chat-skeleton"></div>
|
||||
<div class="chat-skeleton"></div>
|
||||
</div>
|
||||
<p v-else-if="chat.membersState === 'error' && !chat.members.size" class="chat-error" role="alert">
|
||||
{{ t('chat.picker.failed') }}
|
||||
<button class="chat-link-btn" type="button" @click="chat.loadMembers(true)">{{ t('chat.retry') }}</button>
|
||||
</p>
|
||||
<p v-else-if="!others.length" class="chat-muted">{{ t('chat.picker.nobody') }}</p>
|
||||
<p v-else-if="!results.length" class="chat-muted">{{ t('chat.picker.noMatch', { q: q.trim() }) }}</p>
|
||||
<ul v-else class="chat-rows">
|
||||
<li v-for="m in results" :key="m.id">
|
||||
<button class="chat-row chat-picker-row" type="button" :disabled="busy" @click="pick(m.id)">
|
||||
<ChatAvatar :user-id="m.id" :member="m" :size="24" />
|
||||
<span class="chat-row-name">{{ fullName(m) }}</span>
|
||||
<span class="chat-pop-meta">@{{ m.handle }}</span>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</dialog>
|
||||
</template>
|
||||
Reference in New Issue
Block a user