diff --git a/src/components/chat/SidePanel.vue b/src/components/chat/SidePanel.vue index 2c15c5b..0fe88c6 100644 --- a/src/components/chat/SidePanel.vue +++ b/src/components/chat/SidePanel.vue @@ -68,7 +68,7 @@ import { defineComponent } from 'vue'; import { ElSkeleton, ElInput } from 'element-plus'; import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'; -import { ROUTE_CHAT_CONVERSATION, ROUTE_CHAT_CONVERSATION_NEW } from '@/router/constants'; +import { ROUTE_CHAT_CONVERSATION } from '@/router/constants'; import { chatOperator } from '@/operators'; import { IChatConversation } from '@/operators/chat/models'; import { Status } from '@/store/common/models'; diff --git a/src/pages/chat/Conversation.vue b/src/pages/chat/Conversation.vue index c2396df..ecb200e 100644 --- a/src/pages/chat/Conversation.vue +++ b/src/pages/chat/Conversation.vue @@ -63,15 +63,18 @@ export default defineComponent({ }, computed: { messages() { - return ( - this.$store.state.chat.conversations?.find( - (conversation: IChatConversation) => conversation.id === this.$route.params.id?.toString() - )?.messages || [] - ); + return this.$store.state.chat.conversations?.find( + (conversation: IChatConversation) => conversation.id === this.$route.params.id?.toString() + )?.messages; }, conversationId(): string | undefined { return this.$route.params.id?.toString(); }, + conversation() { + return this.$store.state.chat.conversations?.find( + (conversation: IChatConversation) => conversation.id === this.conversationId + ); + }, application() { return this.applications?.find((application: IApplication) => application.api?.id === this.model.apiId); }, @@ -85,9 +88,21 @@ export default defineComponent({ return this.$store.state.chat.getApplicationsStatus === Status.Request; } }, + watch: { + conversationId() { + if (!this.conversation) { + this.onCreateNewConversation(this.conversationId); + } + } + }, + mounted() { + if (!this.conversation) { + this.onCreateNewConversation(this.conversationId); + } + }, methods: { - async onCreateNewConversation() { - const newConversationId = uuid(); + async onCreateNewConversation(id?: string) { + const newConversationId = id || uuid(); await this.$router.push({ name: ROUTE_CHAT_CONVERSATION, params: { @@ -117,10 +132,6 @@ export default defineComponent({ this.question = ''; await this.onFetchAnswer(); }, - async onFetchHistory(id?: string) { - const { data: data } = await chatOperator.getConversation(id || this.conversationId); - this.messages = data.messages || []; - }, async onFetchAnswer() { const token = this.application?.credential?.token; const endpoint = this.application?.api?.endpoint; @@ -153,14 +164,6 @@ export default defineComponent({ content: response.answer, state: IChatMessageState.ANSWERING }; - if (!this.conversationId) { - this.$router.push({ - name: ROUTE_CHAT_CONVERSATION, - params: { - id: response.conversation_id - } - }); - } } } )