From eaa685043164f92c11b040c02ee5ba7de8e50e94 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 22 Feb 2024 17:53:58 -0800 Subject: [PATCH] Update Messages.svelte --- src/lib/components/chat/Messages.svelte | 28 ++++++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/lib/components/chat/Messages.svelte b/src/lib/components/chat/Messages.svelte index 7766b348d..20a6fccad 100644 --- a/src/lib/components/chat/Messages.svelte +++ b/src/lib/components/chat/Messages.svelte @@ -223,20 +223,32 @@ }, 100); }; - const deleteMessageAndDescendants = async (messageId: string) => { + // TODO: change delete behaviour + // const deleteMessageAndDescendants = async (messageId: string) => { + // if (history.messages[messageId]) { + // history.messages[messageId].deleted = true; + + // for (const childId of history.messages[messageId].childrenIds) { + // await deleteMessageAndDescendants(childId); + // } + // } + // }; + + // const triggerDeleteMessageRecursive = async (messageId: string) => { + // await deleteMessageAndDescendants(messageId); + // await updateChatById(localStorage.token, chatId, { history }); + // await chats.set(await getChatList(localStorage.token)); + // }; + + const messageDeleteHandler = async (messageId) => { if (history.messages[messageId]) { history.messages[messageId].deleted = true; for (const childId of history.messages[messageId].childrenIds) { - await deleteMessageAndDescendants(childId); + history.messages[childId].deleted = true; } } - }; - - const triggerDeleteMessageRecursive = async (messageId: string) => { - await deleteMessageAndDescendants(messageId); await updateChatById(localStorage.token, chatId, { history }); - await chats.set(await getChatList(localStorage.token)); }; @@ -255,7 +267,7 @@ > {#if message.role === 'user'} triggerDeleteMessageRecursive(message.id)} + on:delete={() => messageDeleteHandler(message.id)} user={$user} {message} isFirstMessage={messageIdx === 0}