From ca73de6c8bd15969b9a009dc42508f58495334e0 Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 27 Mar 2023 01:06:28 +0800 Subject: [PATCH] feat: implement delete connection/chat --- components/ClearDataConfirmModal.tsx | 2 +- components/ConnectionSidebar.tsx | 46 +++++++++++++++++++++++++--- components/SettingModal.tsx | 16 +++++----- package.json | 1 - pnpm-lock.yaml | 14 --------- store/chat.ts | 7 +++++ store/connection.ts | 34 ++++++-------------- 7 files changed, 67 insertions(+), 53 deletions(-) diff --git a/components/ClearDataConfirmModal.tsx b/components/ClearDataConfirmModal.tsx index 3396aed..37bb328 100644 --- a/components/ClearDataConfirmModal.tsx +++ b/components/ClearDataConfirmModal.tsx @@ -13,7 +13,7 @@ const ClearDataConfirmModal = (props: Props) => { toast.success("Message cleared. The page will be reloaded."); setTimeout(() => { window.location.reload(); - }, 1500); + }, 300); }; return ( diff --git a/components/ConnectionSidebar.tsx b/components/ConnectionSidebar.tsx index b2588f6..e81956d 100644 --- a/components/ConnectionSidebar.tsx +++ b/components/ConnectionSidebar.tsx @@ -50,10 +50,21 @@ const ConnectionSidebar = () => { }); }; + const handleDeleteConnection = (connection: Connection) => { + connectionStore.clearConnection((item) => item.id !== connection.id); + if (currentConnectionCtx?.connection.id === connection.id) { + connectionStore.setCurrentConnectionCtx(undefined); + } + }; + const handleDatabaseNameSelect = async (databaseName: string) => { + if (!currentConnectionCtx?.connection) { + return; + } + const database = databaseList.find((database) => database.name === databaseName); connectionStore.setCurrentConnectionCtx({ - connection: currentConnectionCtx!.connection, + connection: currentConnectionCtx.connection, database: database, }); }; @@ -71,6 +82,13 @@ const ConnectionSidebar = () => { layoutStore.toggleSidebar(false); }; + const handleDeleteChat = (chat: Chat) => { + chatStore.clearChat((item) => item.id !== chat.id); + if (chatStore.currentChat?.id === chat.id) { + chatStore.setCurrentChat(undefined); + } + }; + return ( <>