- createChatClient: bearer auth, one refresh-and-retry on 401, 422 field errors
- useChat over useState: host bootstrap, open a channel, send
- ChatPage, ChatChannelList, ChatMessageList, ChatComposer
- runtime config chat.apiBase, public.chat.{apiBase,channelsApiBase,botsApiBase,hostApiBase}
29 lines
928 B
Vue
29 lines
928 B
Vue
<script setup lang="ts">
|
|
// The message form: Enter sends, Shift+Enter adds a line.
|
|
const props = defineProps<{ conversationId: number }>()
|
|
const { t } = useI18n()
|
|
const chat = useChat()
|
|
|
|
const text = computed({
|
|
get: () => chat.drafts.value[props.conversationId] ?? '',
|
|
set: (v: string) => (chat.drafts.value[props.conversationId] = v),
|
|
})
|
|
|
|
async function submit() {
|
|
await chat.send(text.value)
|
|
}
|
|
|
|
function onKeydown(e: KeyboardEvent) {
|
|
if (e.isComposing || e.key !== 'Enter' || e.shiftKey) return
|
|
e.preventDefault()
|
|
void submit()
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<form class="chat-composer" @submit.prevent="submit">
|
|
<textarea v-model="text" class="chat-composer-input" rows="2" :aria-label="t('chat.message')" :readonly="chat.sending.value" @keydown="onKeydown"></textarea>
|
|
<button class="chat-send" type="submit" :disabled="!text.trim() || chat.sending.value">{{ t('chat.send') }}</button>
|
|
</form>
|
|
</template>
|