Files
vue-chat-layer/app/components/Chat/Page.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

46 lines
1.7 KiB
Vue

<script setup lang="ts">
// The full chat: a sidebar with the channels and the DMs, and the open
// conversation. On a narrow screen one of them shows at a time. Render it
// inside <ClientOnly> (it uses window and the DOM); it starts the chat
// store itself.
//
// Slots: sidebar-footer (below the channel list).
const { t, locale, localeProperties } = useI18n()
const chat = useChat()
const picker = ref<{ open: () => void } | null>(null)
const panel = ref<{ focus: () => void } | null>(null)
const formatLocale = computed(() => (localeProperties.value as { language?: string } | undefined)?.language || locale.value)
onMounted(() => {
void chat.start(formatLocale.value)
})
const open = computed(() => chat.activeId !== null)
function opened() {
panel.value?.focus()
}
</script>
<template>
<div class="chat-page" :class="{ 'is-open': open }">
<p v-if="chat.bootstrapState === 'error' && chat.member === undefined" class="chat-error" role="alert">
{{ t('chat.error.bootstrap') }}
<button class="chat-link-btn" type="button" @click="chat.start(formatLocale)">{{ t('chat.retry') }}</button>
</p>
<p v-else-if="chat.member === false" class="chat-muted">{{ t('chat.notMember') }}</p>
<template v-else>
<aside class="chat-sidebar">
<ChatChannelList @opened="opened">
<template #sidebar-footer><slot name="sidebar-footer" /></template>
</ChatChannelList>
<ChatDmList @compose="picker?.open()" @opened="opened" />
</aside>
<ChatPanel ref="panel" class="chat-main" @back="chat.close()" />
<ChatMemberPicker ref="picker" @started="opened" />
</template>
<ChatNotices />
</div>
</template>