modify delete chat message method

This commit is contained in:
chungyau97
2023-09-19 21:39:37 +08:00
parent 922ba896ec
commit 51f9f0be04
3 changed files with 21 additions and 9 deletions
@@ -163,6 +163,7 @@ export const ChatMessage = ({ open, chatflowid, isDialog }) => {
if (!chatId) {
setChatId(data.chatId)
localStorage.setItem(`${chatflowid}_INTERNAL`, data.chatId)
}
if (!isChatFlowAvailableToStream) {
setMessages((prevMessages) => [
@@ -200,8 +201,10 @@ export const ChatMessage = ({ open, chatflowid, isDialog }) => {
// Get chatmessages successful
useEffect(() => {
if (getChatmessageApi.data) {
setChatId(getChatmessageApi.data[0]?.chatId)
if (getChatmessageApi.data?.length) {
const chatId = getChatmessageApi.data[0]?.chatId
setChatId(chatId)
localStorage.setItem(`${chatflowid}_INTERNAL`, chatId)
const loadedMessages = getChatmessageApi.data.map((message) => {
const obj = {
message: message.content,
@@ -85,7 +85,9 @@ export const ChatPopUp = ({ chatflowid }) => {
if (isConfirmed) {
try {
await chatmessageApi.deleteChatmessage(chatflowid)
const chatId = localStorage.getItem(`${chatflowid}_INTERNAL`)
await chatmessageApi.deleteChatmessage(chatId)
localStorage.removeItem(`${chatflowid}_INTERNAL`)
resetChatDialog()
enqueueSnackbar({
message: 'Succesfully cleared all chat history',