From 941bcdc2e541aaa2e1f1964e43991eff81d0ce5d Mon Sep 17 00:00:00 2001 From: Danny Liu Date: Tue, 20 Feb 2024 15:12:06 -0800 Subject: [PATCH] Refactor deleteMessage function and update deleteMessagePair usage --- src/lib/components/chat/Messages.svelte | 13 ++++++------- src/lib/components/chat/Messages/UserMessage.svelte | 8 +++++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/lib/components/chat/Messages.svelte b/src/lib/components/chat/Messages.svelte index 53292027..a4a5ffa2 100644 --- a/src/lib/components/chat/Messages.svelte +++ b/src/lib/components/chat/Messages.svelte @@ -221,14 +221,13 @@ scrollToBottom(); }, 100); }; - - const deleteMessage = async (messageId) => { + + const deleteMessagePair = async (messageId) => { history.messages[messageId].deleted = true; history.messages[history.messages[messageId].childrenIds[0]].deleted = true; - updateChatById(localStorage.token, chatId, { - messages: messages, - history: history - }); + + await updateChatById(localStorage.token, chatId, { history }); + await chats.set(await getChatList(localStorage.token)); }; @@ -247,7 +246,7 @@ > {#if message.role === 'user'} deleteMessage(message.id)} + on:delete={() => deleteMessagePair(message.id)} user={$user} {message} isFirstMessage={messageIdx === 0} diff --git a/src/lib/components/chat/Messages/UserMessage.svelte b/src/lib/components/chat/Messages/UserMessage.svelte index 7dfca9e3..ca1cff59 100644 --- a/src/lib/components/chat/Messages/UserMessage.svelte +++ b/src/lib/components/chat/Messages/UserMessage.svelte @@ -45,6 +45,10 @@ edit = false; editedContent = ''; }; + + const deleteMessageHandler = async () => { + dispatch('delete', message.id); + };
@@ -288,7 +292,9 @@ {#if !isFirstMessage}