Skip to content

Commit

Permalink
Refactor chat store and session sync logic (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
swuecho authored Jul 9, 2024
1 parent 02f37ba commit 25d1bf4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions web/src/store/modules/chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
deleteChatSession,
updateChatSession as fetchUpdateChatByUuid,
getChatSessionDefault,
getChatMessagesBySessionUUID as getChatSessionHistory,
getChatMessagesBySessionUUID,
getChatSessionsByUser,
getUserActiveChatSession,
renameChatSession,
Expand Down Expand Up @@ -82,9 +82,11 @@ export const useChatStore = defineStore('chat-store', {

async syncChatMessages(need_uuid: string) {
if (need_uuid) {
const messageData = await getChatSessionHistory(need_uuid)
const messageData = await getChatMessagesBySessionUUID(need_uuid)
this.chat[need_uuid] = messageData
// this.reloadRoute(need_uuid) // !!! this cause cycle
await createOrUpdateUserActiveChatSession(need_uuid)
this.setActiveLocal(need_uuid)
//await this.reloadRoute(this.active) // !!! this cause cycle
}
},

Expand All @@ -93,7 +95,7 @@ export const useChatStore = defineStore('chat-store', {
this.history.unshift(history)
this.chat[history.uuid] = chatData
this.active = history.uuid
this.reloadRoute(history.uuid)
this.reloadRoute(this.active)
},

async updateChatSession(uuid: string, edit: Partial<Chat.Session>) {
Expand Down
1 change: 1 addition & 0 deletions web/src/views/chat/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const { scrollRef, scrollToBottom } = useScroll()
// session uuid
const { uuid: sessionUuid } = route.params as { uuid: string }
chatStore.syncChatMessages(sessionUuid)
const dataSources = computed(() => chatStore.getChatSessionDataByUuid(sessionUuid))
const chatSession = computed(() => chatStore.getChatSessionByUuid(sessionUuid))
Expand Down

0 comments on commit 25d1bf4

Please sign in to comment.