From f56da1a39fb3e1544065f1f96758750343ecfae4 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 15 Jun 2024 04:41:48 -0600 Subject: [PATCH] refac --- src/lib/components/layout/Sidebar.svelte | 43 +++++++++++++++++-- .../components/layout/Sidebar/ChatItem.svelte | 35 +-------------- 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 3b32e6016..e844d4f39 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -1,4 +1,5 @@ + { + deleteChatHandler(deleteChat.id); + }} +> +
+ This will delete {deleteChat.title}. +
+
+ {#if $showSidebar} @@ -433,6 +464,10 @@ on:select={() => { selectedChatId = chat.id; }} + on:delete={() => { + deleteChat = chat; + showDeleteConfirm = true; + }} /> {/each} diff --git a/src/lib/components/layout/Sidebar/ChatItem.svelte b/src/lib/components/layout/Sidebar/ChatItem.svelte index 1273def18..150490690 100644 --- a/src/lib/components/layout/Sidebar/ChatItem.svelte +++ b/src/lib/components/layout/Sidebar/ChatItem.svelte @@ -17,7 +17,6 @@ import ChatMenu from './ChatMenu.svelte'; import ShareChatModal from '$lib/components/chat/ShareChatModal.svelte'; - import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte'; import GarbageBin from '$lib/components/icons/GarbageBin.svelte'; import Tooltip from '$lib/components/common/Tooltip.svelte'; import ArchiveBox from '$lib/components/icons/ArchiveBox.svelte'; @@ -28,9 +27,7 @@ let mouseOver = false; - let showDeleteConfirmDialog = false; let showShareChatModal = false; - let confirmEdit = false; let chatTitle = chat.title; @@ -46,22 +43,6 @@ } }; - const deleteChat = async (id) => { - const res = await deleteChatById(localStorage.token, id).catch((error) => { - toast.error(error); - return null; - }); - - if (res) { - if ($chatId === id) { - await chatId.set(''); - await tick(); - goto('/'); - } - await chats.set(await getChatList(localStorage.token)); - } - }; - const cloneChatHandler = async (id) => { const res = await cloneChatById(localStorage.token, id).catch((error) => { toast.error(error); @@ -86,18 +67,6 @@ - { - deleteChat(chat.id); - }} -> -
- This will delete {chat.title}. -
-
-
{#if confirmEdit}
{ - showDeleteConfirmDialog = true; + dispatch('delete'); }} onClose={() => { selected = false; @@ -291,7 +260,7 @@ id="delete-chat-button" class="hidden" on:click={() => { - showDeleteConfirmDialog = true; + dispatch('delete'); }} >