Skip to content

Commit

Permalink
Merge pull request #375 from shunyue1320/change-session-abort-chat
Browse files Browse the repository at this point in the history
feat: abort chat when change chat session
  • Loading branch information
satrong authored Apr 27, 2024
2 parents 90f1427 + e3bd2db commit 410141a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions components/Chat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ async function saveMessage(data: Omit<ChatHistory, 'sessionId'>) {
? await clientDB.chatHistories.add({ ...data, sessionId: props.sessionId })
: Math.random()
}
defineExpose({ abortChat: onAbortChat })
</script>

<template>
Expand Down
13 changes: 10 additions & 3 deletions pages/chat/index.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<script setup lang="ts">
import type { ComponentInstance } from 'vue'
import ChatSessionList from '~/components/ChatSessionList.vue'
import { type Message } from '~/components/Chat.vue'
import Chat, { type Message } from '~/components/Chat.vue'
export interface ChatSessionSettings extends Partial<Omit<ChatSession, 'id' | 'createTime'>> { }
const chatSessionListRef = shallowRef<ComponentInstance<typeof ChatSessionList>>()
const chatRef = shallowRef<ComponentInstance<typeof Chat>>()
const sessionId = ref(0)
const latestMessageId = ref(0)
Expand Down Expand Up @@ -33,15 +35,20 @@ function onMessage(data: Message | null) {
function onNewChat() {
chatSessionListRef.value?.createChat()
}
function onChangeChatSession(id: number) {
sessionId.value = id
chatRef.value?.abortChat()
}
</script>

<template>
<div class="h-full max-w-6xl mx-auto flex flex-1 border border-gray-200 dark:border-gray-800 rounded-md shadow-md"
style="--chat-side-width:240px">
<ChatSessionList ref="chatSessionListRef"
class="shrink-0 w-[var(--chat-side-width)]"
@select="id => sessionId = id" />
<chat v-if="sessionId > 0"
@select="onChangeChatSession" />
<chat ref="chatRef" v-if="sessionId > 0"
class="flex-1 px-4 pb-4 box-border w-[calc(100%-var(--chat-side-width))]"
:session-id="sessionId"
@change-settings="onChangeSettings"
Expand Down

0 comments on commit 410141a

Please sign in to comment.