From 0f75de02cbadbb5623176276528894e71aa01344 Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Sun, 10 Nov 2024 18:08:05 +0530 Subject: [PATCH] Fix: Update temporary chat history This commit addresses an issue where temporary chat history was not being updated correctly when using voice input. The `setHistoryId` function is now called within the `saveMessageOnError` function to ensure that the history ID is set correctly when a message is saved. --- src/hooks/useMessageOption.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/hooks/useMessageOption.tsx b/src/hooks/useMessageOption.tsx index 90fc06a..322287c 100644 --- a/src/hooks/useMessageOption.tsx +++ b/src/hooks/useMessageOption.tsx @@ -366,6 +366,8 @@ export const useMessageOption = () => { const saveMessageOnSuccess = async (e: any) => { if (!temporaryChat) { return await saveSuccess(e) + } else { + setHistoryId("temp") } return true @@ -374,6 +376,21 @@ export const useMessageOption = () => { const saveMessageOnError = async (e: any) => { if (!temporaryChat) { return await saveError(e) + } else { + setHistory([ + ...history, + { + role: "user", + content: e.userMessage, + image: e.image + }, + { + role: "assistant", + content: e.botMessage + } + ]) + + setHistoryId("temp") } return true @@ -1069,6 +1086,6 @@ export const useMessageOption = () => { setSelectedKnowledge, ttsEnabled, temporaryChat, - setTemporaryChat, + setTemporaryChat } }