Refactor deleteMessage function and update deleteMessagePair usage

This commit is contained in:
Danny Liu 2024-02-20 15:12:06 -08:00
parent cd3cecd2f0
commit 941bcdc2e5
2 changed files with 13 additions and 8 deletions

View File

@ -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));
};
</script>
@ -247,7 +246,7 @@
>
{#if message.role === 'user'}
<UserMessage
on:delete={() => deleteMessage(message.id)}
on:delete={() => deleteMessagePair(message.id)}
user={$user}
{message}
isFirstMessage={messageIdx === 0}

View File

@ -45,6 +45,10 @@
edit = false;
editedContent = '';
};
const deleteMessageHandler = async () => {
dispatch('delete', message.id);
};
</script>
<div class=" flex w-full">
@ -288,7 +292,9 @@
{#if !isFirstMessage}
<button
class="invisible group-hover:visible p-1 rounded dark:hover:text-white transition"
on:click={() => dispatch('delete', { messageId: message.id })}
on:click={() => {
deleteMessageHandler();
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"