From 60c99a44f8cacd687ae0e3cea123365a1506c567 Mon Sep 17 00:00:00 2001 From: Danny Liu Date: Tue, 20 Feb 2024 13:24:22 -0800 Subject: [PATCH] remove user message and response from DOM as pair --- src/lib/components/chat/Messages.svelte | 166 ++++++++++-------- .../chat/Messages/UserMessage.svelte | 8 +- 2 files changed, 93 insertions(+), 81 deletions(-) diff --git a/src/lib/components/chat/Messages.svelte b/src/lib/components/chat/Messages.svelte index 082b65fc2..53292027d 100644 --- a/src/lib/components/chat/Messages.svelte +++ b/src/lib/components/chat/Messages.svelte @@ -221,6 +221,15 @@ scrollToBottom(); }, 100); }; + + const deleteMessage = async (messageId) => { + history.messages[messageId].deleted = true; + history.messages[history.messages[messageId].childrenIds[0]].deleted = true; + updateChatById(localStorage.token, chatId, { + messages: messages, + history: history + }); + }; {#if messages.length == 0} @@ -229,90 +238,93 @@
{#key chatId} {#each messages as message, messageIdx} -
-
- {#if message.role === 'user'} - message.parentId === null) - .map((message) => message.id) ?? []} - {confirmEditMessage} - {showPreviousMessage} - {showNextMessage} - {copyToClipboard} - /> + {#if !message.deleted} +
+
+ {#if message.role === 'user'} + deleteMessage(message.id)} + user={$user} + {message} + isFirstMessage={messageIdx === 0} + siblings={message.parentId !== null + ? history.messages[message.parentId]?.childrenIds ?? [] + : Object.values(history.messages) + .filter((message) => message.parentId === null) + .map((message) => message.id) ?? []} + {confirmEditMessage} + {showPreviousMessage} + {showNextMessage} + {copyToClipboard} + /> - {#if messages.length - 1 === messageIdx && processing !== ''} -
-
-
+
+ + @keyframes spinner_8HQG { + 0%, + 57.14% { + animation-timing-function: cubic-bezier(0.33, 0.66, 0.66, 1); + transform: translate(0); + } + 28.57% { + animation-timing-function: cubic-bezier(0.33, 0, 0.66, 0.33); + transform: translateY(-6px); + } + 100% { + transform: translate(0); + } + } + +
+
+ {processing} +
-
- {processing} -
-
+ {/if} + {:else} + {/if} - {:else} - - {/if} +
-
+ {/if} {/each} {#if bottomPadding} diff --git a/src/lib/components/chat/Messages/UserMessage.svelte b/src/lib/components/chat/Messages/UserMessage.svelte index f64b98df8..7dfca9e36 100644 --- a/src/lib/components/chat/Messages/UserMessage.svelte +++ b/src/lib/components/chat/Messages/UserMessage.svelte @@ -1,11 +1,13 @@